Skip to content

Commit ce9e20a

Browse files
authored
Rollup merge of rust-lang#105207 - RalfJung:interpret-clobber-return, r=oli-obk
interpret: clobber return place when calling function Makes sure the callee cannot observe the previous contents of the return place, and the caller cannot read any of the old return place contents even if the function unwinds. I don't think we can test for this though, that would require some strange hand-written MIR. r? ``@oli-obk``
2 parents 203c876 + 51ac2af commit ce9e20a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Diff for: compiler/rustc_const_eval/src/interpret/eval_context.rs

+4
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
676676
return_to_block: StackPopCleanup,
677677
) -> InterpResult<'tcx> {
678678
trace!("body: {:#?}", body);
679+
// Clobber previous return place contents, nobody is supposed to be able to see them any more
680+
// This also checks dereferenceable, but not align. We rely on all constructed places being
681+
// sufficiently aligned (in particular we rely on `deref_operand` checking alignment).
682+
self.write_uninit(return_place)?;
679683
// first push a stack frame so we have access to the local substs
680684
let pre_frame = Frame {
681685
body,

0 commit comments

Comments
 (0)