adjust frame_in_std to recognize std tests

This commit is contained in:
Ralf Jung 2024-04-02 08:23:38 +02:00
parent 9e35555474
commit c2e4916cf8

View File

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