]> git.lizzy.rs Git - rust.git/commitdiff
fix unsized extern types
authorRalf Jung <post@ralfj.de>
Sun, 26 Aug 2018 12:35:15 +0000 (14:35 +0200)
committerRalf Jung <post@ralfj.de>
Tue, 28 Aug 2018 17:57:05 +0000 (19:57 +0200)
src/librustc_mir/interpret/operand.rs
src/librustc_mir/interpret/place.rs

index 9aba7c78caf929739a6519dd1b7219d210fa0a59..9681b705d7eba1d28f8e2a5efee2fb4025ccd6be 100644 (file)
@@ -232,8 +232,7 @@ pub(super) fn try_read_value_from_mplace(
         &self,
         mplace: MPlaceTy<'tcx>,
     ) -> EvalResult<'tcx, Option<Value>> {
-        debug_assert_eq!(mplace.extra.is_some(), mplace.layout.is_unsized());
-        if mplace.extra.is_some() {
+        if mplace.layout.is_unsized() {
             // Dont touch unsized
             return Ok(None);
         }
index 0411256520203c3a53f738b95c607d7525c4b51b..0a6fef3008433c04283d247bbba0d41a357cf315 100644 (file)
@@ -32,6 +32,8 @@ pub struct MemPlace {
     pub ptr: Scalar,
     pub align: Align,
     /// Metadata for unsized places.  Interpretation is up to the type.
+    /// Must not be present for sized types, but can be missing for unsized types
+    /// (e.g. `extern type`).
     pub extra: Option<Scalar>,
 }
 
@@ -236,11 +238,12 @@ pub fn ref_to_mplace(
     ) -> EvalResult<'tcx, MPlaceTy<'tcx>> {
         let pointee_type = val.layout.ty.builtin_deref(true).unwrap().ty;
         let layout = self.layout_of(pointee_type)?;
-        let mplace = if layout.is_unsized() {
-            let (ptr, extra) = val.to_scalar_pair()?;
-            MemPlace { ptr, align: layout.align, extra: Some(extra) }
-        } else {
-            MemPlace { ptr: val.to_scalar()?, align: layout.align, extra: None }
+        let align = layout.align;
+        let mplace = match *val {
+            Value::Scalar(ptr) =>
+                MemPlace { ptr: ptr.not_undef()?, align, extra: None },
+            Value::ScalarPair(ptr, extra) =>
+                MemPlace { ptr: ptr.not_undef()?, align, extra: Some(extra.not_undef()?) },
         };
         Ok(MPlaceTy { mplace, layout })
     }