Skip to content

Commit

Permalink
interpret: always enable write_immediate sanity checks
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Sep 29, 2024
1 parent 1d9162b commit 7f48538
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_const_eval/src/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(..)));
}
}
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_const_eval/src/interpret/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,10 +651,10 @@ where
if !self.validation_in_progress() {
M::after_local_write(self, local, /*storage_live*/ false)?;
}
// Double-check that the value we are storing and the local fit to each other.
if cfg!(debug_assertions) {
src.assert_matches_abi(local_layout.abi, self);
}
// Double-check that the value we are storing and the local fit to each other. We do
// this even with debug assertions as interpreter behavior can get really strange
// when this is violated.
src.assert_matches_abi(local_layout.abi, self);
}
Left(mplace) => {
self.write_immediate_to_mplace_no_validate(src, mplace.layout, mplace.mplace)?;
Expand All @@ -672,6 +672,7 @@ where
layout: TyAndLayout<'tcx>,
dest: MemPlace<M::Provenance>,
) -> InterpResult<'tcx> {
// Ensure the value matches the type of the place it is written to.
if cfg!(debug_assertions) {
value.assert_matches_abi(layout.abi, self);
}
Expand Down

0 comments on commit 7f48538

Please sign in to comment.