]> git.lizzy.rs Git - rust.git/commitdiff
Move recursion check for zsts back to read site instead of access check site.
authorOliver Scherer <github35764891676564198441@oli-obk.de>
Fri, 1 May 2020 13:52:08 +0000 (15:52 +0200)
committerOliver Scherer <github35764891676564198441@oli-obk.de>
Fri, 1 May 2020 13:52:08 +0000 (15:52 +0200)
src/librustc_mir/interpret/memory.rs
src/librustc_mir/interpret/operand.rs
src/test/ui/consts/static-ice.rs [new file with mode: 0644]

index d1881524172cc840036c12d2882255ae58a32737..39e428cee1d7bee2088cab7227383326f615150b 100644 (file)
@@ -400,18 +400,7 @@ fn check_offset_align(offset: u64, align: Align) -> InterpResult<'static> {
 
                 // We can still be zero-sized in this branch, in which case we have to
                 // return `None`.
-                if size.bytes() == 0 {
-                    // We may be reading from a static.
-                    // In order to ensure that `static FOO: Type = FOO;` causes a cycle error
-                    // instead of magically pulling *any* ZST value from the ether, we need to
-                    // actually access the referenced allocation. The caller is likely
-                    // to short-circuit on `None`, so we trigger the access here to
-                    // make sure it happens.
-                    self.get_raw(ptr.alloc_id)?;
-                    None
-                } else {
-                    Some(ptr)
-                }
+                if size.bytes() == 0 { None } else { Some(ptr) }
             }
         })
     }
index b924f20ce7cc83afc855023fd9bf6f2b5e23a9b8..05844eb126c59bec3d2f57a32d4efcee91975614 100644 (file)
@@ -240,6 +240,15 @@ fn try_read_immediate_from_mplace(
         {
             Some(ptr) => ptr,
             None => {
+                if let Scalar::Ptr(ptr) = mplace.ptr {
+                    // We may be reading from a static.
+                    // In order to ensure that `static FOO: Type = FOO;` causes a cycle error
+                    // instead of magically pulling *any* ZST value from the ether, we need to
+                    // actually access the referenced allocation. The caller is likely
+                    // to short-circuit on `None`, so we trigger the access here to
+                    // make sure it happens.
+                    self.memory.get_raw(ptr.alloc_id)?;
+                }
                 return Ok(Some(ImmTy {
                     // zero-sized type
                     imm: Scalar::zst().into(),
diff --git a/src/test/ui/consts/static-ice.rs b/src/test/ui/consts/static-ice.rs
new file mode 100644 (file)
index 0000000..a6d90e4
--- /dev/null
@@ -0,0 +1,27 @@
+// check-pass
+
+#[derive(Copy, Clone)]
+pub struct Glfw;
+
+static mut GLFW: Option<Glfw> = None;
+pub fn new() -> Glfw {
+    unsafe {
+        if let Some(glfw) = GLFW {
+            return glfw;
+        } else {
+            todo!()
+        }
+    };
+}
+
+extern "C" {
+    static _dispatch_queue_attr_concurrent: [u8; 0];
+}
+
+static DISPATCH_QUEUE_CONCURRENT: &'static [u8; 0] =
+    unsafe { &_dispatch_queue_attr_concurrent };
+
+fn main() {
+    *DISPATCH_QUEUE_CONCURRENT;
+    new();
+}