]> git.lizzy.rs Git - rust.git/commitdiff
Properly evaluate zst enum
authorOliver Schneider <git-no-reply-9879165716479413131@oli-obk.de>
Sat, 31 Mar 2018 21:06:26 +0000 (23:06 +0200)
committerAnthony Ramine <n.oxyde@gmail.com>
Thu, 26 Apr 2018 13:07:04 +0000 (15:07 +0200)
src/librustc_mir/interpret/eval_context.rs
src/librustc_mir/interpret/place.rs

index 478f45e841d1c720e0dc6b0e188a3063b9a0fac6..a7cd044cec03a8673ef0cd58f2ed7a23203ac8d0 100644 (file)
@@ -1319,6 +1319,15 @@ pub(crate) fn read_ptr(
     pub fn try_read_value(&self, ptr: Pointer, ptr_align: Align, ty: Ty<'tcx>) -> EvalResult<'tcx, Option<Value>> {
         use syntax::ast::FloatTy;
 
+        let layout = self.layout_of(ty)?;
+        // do the strongest layout check of the two
+        let align = layout.align.max(ptr_align);
+        self.memory.check_align(ptr, align)?;
+
+        if layout.size.bytes() == 0 {
+            return Ok(Some(Value::ByVal(PrimVal::Undef)));
+        }
+
         let ptr = ptr.to_ptr()?;
         let val = match ty.sty {
             ty::TyBool => {
index 456f5fd75db09772ea8949c7c887c71a1ad0cb54..42cb149d68221ed11f8cf5469b37df9f7e4eac05 100644 (file)
@@ -136,6 +136,7 @@ pub fn read_field(
                 let val = [a, b][field_index];
                 Ok(Some((Value::ByVal(val), field.ty)))
             },
+            // FIXME(oli-obk): figure out whether we should be calling `try_read_value` here
             _ => Ok(None),
         }
     }