Skip to content

Commit 7caf2cd

Browse files
committed
interpret: always enable write_immediate sanity checks
1 parent 1d9162b commit 7caf2cd

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

compiler/rustc_const_eval/src/interpret/operand.rs

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ impl<Prov: Provenance> Immediate<Prov> {
118118
(Immediate::Scalar(scalar), Abi::Scalar(s)) => {
119119
assert_eq!(scalar.size(), s.size(cx));
120120
if !matches!(s.primitive(), abi::Pointer(..)) {
121+
// This is not a pointer, it should not carry provenance.
121122
assert!(matches!(scalar, Scalar::Int(..)));
122123
}
123124
}

compiler/rustc_const_eval/src/interpret/place.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,8 @@ where
652652
M::after_local_write(self, local, /*storage_live*/ false)?;
653653
}
654654
// Double-check that the value we are storing and the local fit to each other.
655+
// Things can ge wrong in quite weird ways when this is violated.
656+
// Unfortunately this is too expensive to do in release builds.
655657
if cfg!(debug_assertions) {
656658
src.assert_matches_abi(local_layout.abi, self);
657659
}
@@ -672,9 +674,9 @@ where
672674
layout: TyAndLayout<'tcx>,
673675
dest: MemPlace<M::Provenance>,
674676
) -> InterpResult<'tcx> {
675-
if cfg!(debug_assertions) {
676-
value.assert_matches_abi(layout.abi, self);
677-
}
677+
// We use the sizes from `value` below.
678+
// Ensure that matches the type of the place it is written to.
679+
value.assert_matches_abi(layout.abi, self);
678680
// Note that it is really important that the type here is the right one, and matches the
679681
// type things are read at. In case `value` is a `ScalarPair`, we don't do any magic here
680682
// to handle padding properly, which is only correct if we never look at this data with the

0 commit comments

Comments
 (0)