Skip to content

Commit 7f48538

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

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
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-4
Original file line numberDiff line numberDiff line change
@@ -651,10 +651,10 @@ where
651651
if !self.validation_in_progress() {
652652
M::after_local_write(self, local, /*storage_live*/ false)?;
653653
}
654-
// Double-check that the value we are storing and the local fit to each other.
655-
if cfg!(debug_assertions) {
656-
src.assert_matches_abi(local_layout.abi, self);
657-
}
654+
// Double-check that the value we are storing and the local fit to each other. We do
655+
// this even with debug assertions as interpreter behavior can get really strange
656+
// when this is violated.
657+
src.assert_matches_abi(local_layout.abi, self);
658658
}
659659
Left(mplace) => {
660660
self.write_immediate_to_mplace_no_validate(src, mplace.layout, mplace.mplace)?;
@@ -672,6 +672,7 @@ where
672672
layout: TyAndLayout<'tcx>,
673673
dest: MemPlace<M::Provenance>,
674674
) -> InterpResult<'tcx> {
675+
// Ensure the value matches the type of the place it is written to.
675676
if cfg!(debug_assertions) {
676677
value.assert_matches_abi(layout.abi, self);
677678
}

0 commit comments

Comments
 (0)