Reintroduce some sanity checks

This commit is contained in:
Oliver Schneider 2018-05-13 19:52:53 +02:00 committed by Oliver Schneider
parent 8b99c61701
commit 76ddede5c2
2 changed files with 7 additions and 4 deletions

View File

@ -98,6 +98,13 @@ pub fn value_to_const_value<'tcx>(
mut val: Value,
ty: Ty<'tcx>,
) -> &'tcx ty::Const<'tcx> {
let layout = tcx.layout_of(ty::ParamEnv::reveal_all().and(ty)).unwrap();
match (val, &layout.abi) {
(Value::ByRef(..), _) |
(Value::ByVal(_), &layout::Abi::Scalar(_)) |
(Value::ByValPair(..), &layout::Abi::ScalarPair(..)) => {},
_ => bug!("bad value/layout combo: {:#?}, {:#?}", val, layout),
}
let val = (|| {
// Convert to ByVal or ByValPair if possible
if let Value::ByRef(ptr, align) = val {

View File

@ -1416,10 +1416,6 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
let layout = self.layout_of(ty)?;
self.memory.check_align(ptr, ptr_align)?;
if layout.size.bytes() == 0 {
return Ok(Some(Value::ByVal(PrimVal::Undef)));
}
let ptr = ptr.to_ptr()?;
// Not the right place to do this