Skip to content

Commit 1a92777

Browse files
committed
Auto merge of #122243 - RalfJung:local-place-sanity-check, r=oli-obk
interpret: ensure that Place is never used for a different frame We store the address where the stack frame stores its `locals`. The idea is that even if we pop and push, or switch to a different thread with a larger number of frames, then the `locals` address will most likely change so we'll notice that problem. This is made possible by some recent changes by `@WaffleLapkin,` where we no longer use `Place` across things that change the number of stack frames. I made these debug assertions for now, just to make sure this can't cost us any perf. The first commit is unrelated but it's a one-line comment change so it didn't warrant a separate PR... r? `@oli-obk`
2 parents b62ba94 + 4a349d2 commit 1a92777

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

src/helpers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
413413
.ok_or_else(|| err_ub_format!("callee has fewer arguments than expected"))?;
414414
// Make the local live, and insert the initial value.
415415
this.storage_live(local)?;
416-
let callee_arg = this.local_to_place(this.frame_idx(), local)?;
416+
let callee_arg = this.local_to_place(local)?;
417417
this.write_immediate(*arg, &callee_arg)?;
418418
}
419419
if callee_args.next().is_some() {

src/machine.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1488,14 +1488,13 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
14881488

14891489
fn after_local_allocated(
14901490
ecx: &mut InterpCx<'mir, 'tcx, Self>,
1491-
frame: usize,
14921491
local: mir::Local,
14931492
mplace: &MPlaceTy<'tcx, Provenance>,
14941493
) -> InterpResult<'tcx> {
14951494
let Some(Provenance::Concrete { alloc_id, .. }) = mplace.ptr().provenance else {
14961495
panic!("after_local_allocated should only be called on fresh allocations");
14971496
};
1498-
let local_decl = &ecx.active_thread_stack()[frame].body.local_decls[local];
1497+
let local_decl = &ecx.frame().body.local_decls[local];
14991498
let span = local_decl.source_info.span;
15001499
ecx.machine.allocation_spans.borrow_mut().insert(alloc_id, (span, None));
15011500
Ok(())

0 commit comments

Comments
 (0)