about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-10-02 22:12:06 +0000
committerbors <bors@rust-lang.org>2024-10-02 22:12:06 +0000
commit9c7013c15c189a6978ac8b9dac638581495527de (patch)
tree17a5f1b1eceff1988f1e6aae24ced5f970703554 /compiler/rustc_const_eval/src
parent18b1161ec9eeab8927f91405bca0ddf59a4a26c9 (diff)
parent7caf2cdc2cc50310f556fe07be63b2b85feabc77 (diff)
downloadrust-9c7013c15c189a6978ac8b9dac638581495527de.tar.gz
rust-9c7013c15c189a6978ac8b9dac638581495527de.zip
Auto merge of #131006 - RalfJung:immediate-sanity, r=saethlin
interpret: always enable write_immediate sanity checks

Writing a wrongly-sized scalar somewhere can have quite confusing effects. Let's see how expensive it is to catch this early.
Diffstat (limited to 'compiler/rustc_const_eval/src')
-rw-r--r--compiler/rustc_const_eval/src/interpret/operand.rs1
-rw-r--r--compiler/rustc_const_eval/src/interpret/place.rs8
2 files changed, 6 insertions, 3 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs
index 7e6600060b4..291664d556a 100644
--- a/compiler/rustc_const_eval/src/interpret/operand.rs
+++ b/compiler/rustc_const_eval/src/interpret/operand.rs
@@ -118,6 +118,7 @@ impl<Prov: Provenance> Immediate<Prov> {
             (Immediate::Scalar(scalar), Abi::Scalar(s)) => {
                 assert_eq!(scalar.size(), s.size(cx));
                 if !matches!(s.primitive(), abi::Pointer(..)) {
+                    // This is not a pointer, it should not carry provenance.
                     assert!(matches!(scalar, Scalar::Int(..)));
                 }
             }
diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs
index 449d4c6bd7d..49656e10f2a 100644
--- a/compiler/rustc_const_eval/src/interpret/place.rs
+++ b/compiler/rustc_const_eval/src/interpret/place.rs
@@ -655,6 +655,8 @@ where
                     M::after_local_write(self, local, /*storage_live*/ false)?;
                 }
                 // Double-check that the value we are storing and the local fit to each other.
+                // Things can ge wrong in quite weird ways when this is violated.
+                // Unfortunately this is too expensive to do in release builds.
                 if cfg!(debug_assertions) {
                     src.assert_matches_abi(local_layout.abi, self);
                 }
@@ -675,9 +677,9 @@ where
         layout: TyAndLayout<'tcx>,
         dest: MemPlace<M::Provenance>,
     ) -> InterpResult<'tcx> {
-        if cfg!(debug_assertions) {
-            value.assert_matches_abi(layout.abi, self);
-        }
+        // We use the sizes from `value` below.
+        // Ensure that matches the type of the place it is written to.
+        value.assert_matches_abi(layout.abi, self);
         // Note that it is really important that the type here is the right one, and matches the
         // type things are read at. In case `value` is a `ScalarPair`, we don't do any magic here
         // to handle padding properly, which is only correct if we never look at this data with the