Skip to content

Commit

Permalink
Partially fix miri
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Jul 5, 2024
1 parent 4bf91e1 commit 266c7c2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/tools/miri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ extern crate rustc_index;
extern crate rustc_middle;
extern crate rustc_session;
extern crate rustc_span;
extern crate rustc_symbol_mangling;
extern crate rustc_target;
// Linking `rustc_driver` pulls in the required object code as the rest of the rustc crates are
// shipped only as rmeta files.
Expand Down
27 changes: 13 additions & 14 deletions src/tools/miri/src/shims/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::mir;
use rustc_middle::ty;
use rustc_span::Symbol;
use rustc_symbol_mangling::mangle_internal_symbol;
use rustc_target::{
abi::{Align, Size},
spec::abi::Abi,
Expand Down Expand Up @@ -455,7 +456,9 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
}

// Rust allocation
"__rust_alloc" | "miri_alloc" => {
name if name == mangle_internal_symbol(*this.tcx, "__rust_alloc")
|| name == "miri_alloc" =>
{
let default = |this: &mut MiriInterpCx<'tcx>| {
// 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.
Expand All @@ -466,9 +469,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.check_rustc_alloc_request(size, align)?;

let memory_kind = match link_name.as_str() {
"__rust_alloc" => MiriMemoryKind::Rust,
"miri_alloc" => MiriMemoryKind::Miri,
_ => unreachable!(),
_ => MiriMemoryKind::Rust,
};

let ptr = this.allocate_ptr(
Expand All @@ -481,15 +483,14 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
};

match link_name.as_str() {
"__rust_alloc" => return this.emulate_allocator(default),
"miri_alloc" => {
default(this)?;
return Ok(EmulateItemResult::NeedsReturn);
}
_ => unreachable!(),
_ => return this.emulate_allocator(default),
}
}
"__rust_alloc_zeroed" => {
name if name == mangle_internal_symbol(*this.tcx, "__rust_alloc_zeroed") => {
return this.emulate_allocator(|this| {
// See the comment for `__rust_alloc` why `check_shim` is only called in the
// default case.
Expand All @@ -514,7 +515,9 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.write_pointer(ptr, dest)
});
}
"__rust_dealloc" | "miri_dealloc" => {
name if name == mangle_internal_symbol(*this.tcx, "__rust_dealloc")
|| name == "miri_dealloc" =>
{
let default = |this: &mut MiriInterpCx<'tcx>| {
// See the comment for `__rust_alloc` why `check_shim` is only called in the
// default case.
Expand All @@ -525,9 +528,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
let align = this.read_target_usize(align)?;

let memory_kind = match link_name.as_str() {
"__rust_dealloc" => MiriMemoryKind::Rust,
"miri_dealloc" => MiriMemoryKind::Miri,
_ => unreachable!(),
_ => MiriMemoryKind::Rust,
};

// No need to check old_size/align; we anyway check that they match the allocation.
Expand All @@ -539,17 +541,14 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
};

match link_name.as_str() {
"__rust_dealloc" => {
return this.emulate_allocator(default);
}
"miri_dealloc" => {
default(this)?;
return Ok(EmulateItemResult::NeedsReturn);
}
_ => unreachable!(),
_ => return this.emulate_allocator(default),
}
}
"__rust_realloc" => {
name if name == mangle_internal_symbol(*this.tcx, "__rust_realloc") => {
return this.emulate_allocator(|this| {
// See the comment for `__rust_alloc` why `check_shim` is only called in the
// default case.
Expand Down

0 comments on commit 266c7c2

Please sign in to comment.