Skip to content

Commit

Permalink
more type sanity checks in Miri
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed May 29, 2020
1 parent ad7179d commit c4b6224
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/librustc_mir/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}

Expand Down
8 changes: 8 additions & 0 deletions src/librustc_mir/interpret/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit c4b6224

Please sign in to comment.