about summary refs log tree commit diff
path: root/src/librustc_codegen_ssa
diff options
context:
space:
mode:
authorDan Robertson <dan@dlrobertson.com>2019-02-05 15:52:54 +0000
committerDan Robertson <dan@dlrobertson.com>2019-02-05 21:20:07 +0000
commit80c052bed76d7b7406e956747012bc8a929fe909 (patch)
tree77a17b1ae61363f1c0191da16bee3d4324b2956c /src/librustc_codegen_ssa
parentb2c6b8c29f13f8d1f242da89e587960b95337819 (diff)
downloadrust-80c052bed76d7b7406e956747012bc8a929fe909.tar.gz
rust-80c052bed76d7b7406e956747012bc8a929fe909.zip
Do not ICE in codegen given a extern_type static
The layout of a extern_type static is unsized, but may pass the
Well-Formed check in typeck. As a result, we cannot assume that
a static is sized when generating the `Place` for an r-value.
Diffstat (limited to 'src/librustc_codegen_ssa')
-rw-r--r--src/librustc_codegen_ssa/mir/place.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/librustc_codegen_ssa/mir/place.rs b/src/librustc_codegen_ssa/mir/place.rs
index b10611e5ac7..596f97a0388 100644
--- a/src/librustc_codegen_ssa/mir/place.rs
+++ b/src/librustc_codegen_ssa/mir/place.rs
@@ -41,6 +41,21 @@ impl<'a, 'tcx: 'a, V: CodegenObject> PlaceRef<'tcx, V> {
         }
     }
 
+    fn new_thin_place<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
+        bx: &mut Bx,
+        llval: V,
+        layout: TyLayout<'tcx>,
+        align: Align,
+    ) -> PlaceRef<'tcx, V> {
+        assert!(!bx.cx().type_has_metadata(layout.ty));
+        PlaceRef {
+            llval,
+            llextra: None,
+            layout,
+            align
+        }
+    }
+
     pub fn alloca<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
         bx: &mut Bx,
         layout: TyLayout<'tcx>,
@@ -421,8 +436,10 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
                 }
             }
             mir::Place::Static(box mir::Static { def_id, ty }) => {
+                // NB: The layout of a static may be unsized as is the case when working
+                // with a static that is an extern_type.
                 let layout = cx.layout_of(self.monomorphize(&ty));
-                PlaceRef::new_sized(bx.get_static(def_id), layout, layout.align.abi)
+                PlaceRef::new_thin_place(bx, bx.get_static(def_id), layout, layout.align.abi)
             },
             mir::Place::Projection(box mir::Projection {
                 ref base,