diff options
| author | Ralf Jung <post@ralfj.de> | 2020-05-30 00:02:30 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2020-05-30 00:02:30 +0200 |
| commit | c4b6224ea46f57bb59df8d321d8f40e7f2900423 (patch) | |
| tree | 27d7f3f11f69b9da77aec5ab12111b1f6a5e35f8 /src | |
| parent | ad7179d2a409faaf45465862f44efe7f989cd71e (diff) | |
| download | rust-c4b6224ea46f57bb59df8d321d8f40e7f2900423.tar.gz rust-c4b6224ea46f57bb59df8d321d8f40e7f2900423.zip | |
more type sanity checks in Miri
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_mir/interpret/operand.rs | 12 | ||||
| -rw-r--r-- | src/librustc_mir/interpret/place.rs | 8 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs index f546f6236d7..3cfc331ef8c 100644 --- a/src/librustc_mir/interpret/operand.rs +++ b/src/librustc_mir/interpret/operand.rs @@ -15,8 +15,8 @@ use rustc_target::abi::{Abi, DiscriminantKind, HasDataLayout, LayoutOf, Size}; use rustc_target::abi::{VariantIdx, Variants}; use super::{ - from_known_layout, ConstValue, GlobalId, InterpCx, InterpResult, MPlaceTy, Machine, MemPlace, - Place, PlaceTy, Pointer, Scalar, ScalarMaybeUninit, + from_known_layout, mir_assign_valid_types, ConstValue, GlobalId, InterpCx, InterpResult, + MPlaceTy, Machine, MemPlace, Place, PlaceTy, Pointer, Scalar, ScalarMaybeUninit, }; /// An `Immediate` represents a single immediate self-contained Rust value. @@ -469,6 +469,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { .try_fold(base_op, |op, elem| self.operand_projection(op, elem))?; trace!("eval_place_to_op: got {:?}", *op); + // Sanity-check the type we ended up with. + debug_assert!(mir_assign_valid_types( + *self.tcx, + self.layout_of(self.subst_from_current_frame_and_normalize_erasing_regions( + place.ty(&self.frame().body.local_decls, *self.tcx).ty + ))?, + op.layout, + )); Ok(op) } diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index 6dadb8e4c67..f5e7c1a4823 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -638,6 +638,14 @@ where } self.dump_place(place_ty.place); + // Sanity-check the type we ended up with. + debug_assert!(mir_assign_valid_types( + *self.tcx, + self.layout_of(self.subst_from_current_frame_and_normalize_erasing_regions( + place.ty(&self.frame().body.local_decls, *self.tcx).ty + ))?, + place_ty.layout, + )); Ok(place_ty) } |
