about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2018-08-26 14:35:15 +0200
committerRalf Jung <post@ralfj.de>2018-08-28 19:57:05 +0200
commit066d2eea250c9010358392c93ef40f36cbb9930b (patch)
treeb9f948ac57329dd8935177b324fa4b7e2ce1cefe
parentf96208ca5bd34ba5e9106fe6527db43a9bdc3a8f (diff)
downloadrust-066d2eea250c9010358392c93ef40f36cbb9930b.tar.gz
rust-066d2eea250c9010358392c93ef40f36cbb9930b.zip
fix unsized extern types
-rw-r--r--src/librustc_mir/interpret/operand.rs3
-rw-r--r--src/librustc_mir/interpret/place.rs13
2 files changed, 9 insertions, 7 deletions
diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs
index 9aba7c78caf..9681b705d7e 100644
--- a/src/librustc_mir/interpret/operand.rs
+++ b/src/librustc_mir/interpret/operand.rs
@@ -232,8 +232,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
         &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);
         }
diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs
index 04112565202..0a6fef30084 100644
--- a/src/librustc_mir/interpret/place.rs
+++ b/src/librustc_mir/interpret/place.rs
@@ -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 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
     ) -> 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 })
     }