Fix review comments

Co-authored-by: Ralf Jung <post@ralfj.de>
This commit is contained in:
bjorn3 2023-02-14 00:12:25 +01:00
parent 568deb7ece
commit ffd8cb87bf

View File

@ -359,10 +359,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
match allocator_kind {
AllocatorKind::Global => {
// When `#[global_allocator]` is used, `__rust_*` is defined by the macro expansion
// of this attribute rather than generated by the allocator shim. As such we have
// to call the definition produced by `#[global_allocator]` instead of the shim like
// in the case of `#[global_allocator]` not existing. Somewhat unintuitively doing
// so is done by returning `NotSupported`.
// of this attribute. As such we have to call an exported Rust function,
// and not execute any Miri shim. Somewhat unintuitively doing so is done
// by returning `NotSupported`, which triggers the `lookup_exported_symbol`
// fallback case in `emulate_foreign_item`.
return Ok(EmulateByNameResult::NotSupported);
}
AllocatorKind::Default => {
@ -559,9 +559,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
// Rust allocation
"__rust_alloc" | "miri_alloc" => {
let default = |this: &mut MiriInterpCx<'mir, 'tcx>| {
// Only call `check_shim` when `#[global_allocator]` isn't used. The macro
// expansion of `#[global_allocator]` defines this symbol and `check_shim`
// checks that there exists no definition of a shim.
// Only call `check_shim` when `#[global_allocator]` isn't used. When that
// macro is used, we act like no shim exists, so that the exported function can run.
let [size, align] = this.check_shim(abi, Abi::Rust, link_name, args)?;
let size = this.read_target_usize(size)?;
let align = this.read_target_usize(align)?;