Skip to content

Commit

Permalink
adjust frame_in_std to recognize std tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Apr 4, 2024
1 parent 9e35555 commit c2e4916
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/tools/miri/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -968,10 +968,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {

fn frame_in_std(&self) -> bool {
let this = self.eval_context_ref();
let Some(start_fn) = this.tcx.lang_items().start_fn() else {
// no_std situations
return false;
};
let frame = this.frame();
// Make an attempt to get at the instance of the function this is inlined from.
let instance: Option<_> = try {
Expand All @@ -982,13 +978,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
};
// Fall back to the instance of the function itself.
let instance = instance.unwrap_or(frame.instance);
// Now check if this is in the same crate as start_fn.
// As a special exception we also allow unit tests from
// <https://github.com/rust-lang/miri-test-libstd/tree/master/std_miri_test> to call these
// shims.
// Now check the crate it is in. We could try to be clever here and e.g. check if this is
// the same crate as `start_fn`, but that would not work for running std tests in Miri, so
// we'd need some more hacks anyway. So we just check the name of the crate. If someone
// calls their crate `std` then we'll just let them keep the pieces.
let frame_crate = this.tcx.def_path(instance.def_id()).krate;
frame_crate == this.tcx.def_path(start_fn).krate
|| this.tcx.crate_name(frame_crate).as_str() == "std_miri_test"
let crate_name = this.tcx.crate_name(frame_crate);
let crate_name = crate_name.as_str();
// On miri-test-libstd, the name of the crate is different.
crate_name == "std" || crate_name == "std_miri_test"
}

/// Handler that should be called when unsupported functionality is encountered.
Expand Down

0 comments on commit c2e4916

Please sign in to comment.