about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Schneider <git-no-reply-9879165716479413131@oli-obk.de>2018-05-13 19:52:53 +0200
committerOliver Schneider <github35764891676564198441@oli-obk.de>2018-05-19 14:24:24 +0200
commit76ddede5c2d2abc4c3b97dd383fcd6809384c323 (patch)
treeeb308ef78ad9dcc713ee30926e91e108cf440d51
parent8b99c61701cd3230bb24fba970d2f400e6e09fa1 (diff)
downloadrust-76ddede5c2d2abc4c3b97dd383fcd6809384c323.tar.gz
rust-76ddede5c2d2abc4c3b97dd383fcd6809384c323.zip
Reintroduce some sanity checks
-rw-r--r--src/librustc_mir/interpret/const_eval.rs7
-rw-r--r--src/librustc_mir/interpret/eval_context.rs4
2 files changed, 7 insertions, 4 deletions
diff --git a/src/librustc_mir/interpret/const_eval.rs b/src/librustc_mir/interpret/const_eval.rs
index 1f368cd3dfc..239d9a051c6 100644
--- a/src/librustc_mir/interpret/const_eval.rs
+++ b/src/librustc_mir/interpret/const_eval.rs
@@ -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 {
diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs
index 03137619eda..b91a4ba864a 100644
--- a/src/librustc_mir/interpret/eval_context.rs
+++ b/src/librustc_mir/interpret/eval_context.rs
@@ -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