Skip to content

Commit bc47968

Browse files
authored
Rollup merge of #122076 - WaffleLapkin:mplace-args, r=RalfJung
Tweak the way we protect in-place function arguments in interpreters Use `MPlaceTy` instead of `PlaceTy` in `FnArg` and ignore (copy) locals in an earlier step ("Locals that don't have their address taken are as protected as they can ever be"). This seems to be crucial for tail call support (as they can't refer to caller's locals which are killed when replacing the stack frame). r? `@RalfJung` cc `@oli-obk` see rust-lang/rust#121273 (comment)
2 parents bbab87f + 0d24314 commit bc47968

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

src/machine.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::fmt;
88
use std::path::Path;
99
use std::process;
1010

11-
use either::Either;
1211
use rand::rngs::StdRng;
1312
use rand::Rng;
1413
use rand::SeedableRng;
@@ -962,7 +961,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
962961
// to run extra MIR), and Ok(Some(body)) if we found MIR to run for the
963962
// foreign function
964963
// Any needed call to `goto_block` will be performed by `emulate_foreign_item`.
965-
let args = ecx.copy_fn_args(args)?; // FIXME: Should `InPlace` arguments be reset to uninit?
964+
let args = ecx.copy_fn_args(args); // FIXME: Should `InPlace` arguments be reset to uninit?
966965
let link_name = ecx.item_link_name(instance.def_id());
967966
return ecx.emulate_foreign_item(link_name, abi, &args, dest, ret, unwind);
968967
}
@@ -981,7 +980,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
981980
ret: Option<mir::BasicBlock>,
982981
unwind: mir::UnwindAction,
983982
) -> InterpResult<'tcx> {
984-
let args = ecx.copy_fn_args(args)?; // FIXME: Should `InPlace` arguments be reset to uninit?
983+
let args = ecx.copy_fn_args(args); // FIXME: Should `InPlace` arguments be reset to uninit?
985984
ecx.emulate_dyn_sym(fn_val, abi, &args, dest, ret, unwind)
986985
}
987986

@@ -1334,18 +1333,12 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
13341333

13351334
fn protect_in_place_function_argument(
13361335
ecx: &mut InterpCx<'mir, 'tcx, Self>,
1337-
place: &PlaceTy<'tcx, Provenance>,
1336+
place: &MPlaceTy<'tcx, Provenance>,
13381337
) -> InterpResult<'tcx> {
13391338
// If we have a borrow tracker, we also have it set up protection so that all reads *and
13401339
// writes* during this call are insta-UB.
13411340
let protected_place = if ecx.machine.borrow_tracker.is_some() {
1342-
// Have to do `to_op` first because a `Place::Local` doesn't imply the local doesn't have an address.
1343-
if let Either::Left(place) = ecx.place_to_op(place)?.as_mplace_or_imm() {
1344-
ecx.protect_place(&place)?.into()
1345-
} else {
1346-
// Locals that don't have their address taken are as protected as they can ever be.
1347-
place.clone()
1348-
}
1341+
ecx.protect_place(&place)?.into()
13491342
} else {
13501343
// No borrow tracker.
13511344
place.clone()

0 commit comments

Comments
 (0)