Skip to content

Commit 31da2d9

Browse files
committedJun 11, 2022
Auto merge of #2225 - RalfJung:frame-in-std-inlined, r=RalfJung
make frame_in_std check work with inlining `@InfRandomness` this should help with your trouble in #2215
2 parents 32a7580 + 4da48e0 commit 31da2d9

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed
 

‎src/helpers.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -729,10 +729,22 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
729729

730730
fn frame_in_std(&self) -> bool {
731731
let this = self.eval_context_ref();
732-
this.tcx.lang_items().start_fn().map_or(false, |start_fn| {
733-
this.tcx.def_path(this.frame().instance.def_id()).krate
734-
== this.tcx.def_path(start_fn).krate
735-
})
732+
let Some(start_fn) = this.tcx.lang_items().start_fn() else {
733+
// no_std situations
734+
return false;
735+
};
736+
let frame = this.frame();
737+
// Make an attempt to get at the instance of the function this is inlined from.
738+
let instance: Option<_> = try {
739+
let scope = frame.current_source_info()?.scope;
740+
let inlined_parent = frame.body.source_scopes[scope].inlined_parent_scope?;
741+
let source = &frame.body.source_scopes[inlined_parent];
742+
source.inlined.expect("inlined_parent_scope points to scope without inline info").0
743+
};
744+
// Fall back to the instance of the function itself.
745+
let instance = instance.unwrap_or(frame.instance);
746+
// Now check if this is in the same crate as start_fn.
747+
this.tcx.def_path(instance.def_id()).krate == this.tcx.def_path(start_fn).krate
736748
}
737749

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

0 commit comments

Comments
 (0)
Please sign in to comment.