Skip to content

Commit 6318d24

Browse files
committed
Auto merge of #71751 - oli-obk:const_ice, r=RalfJung
Move recursion check for zsts back to read site instead of access check site Reverts #71140 (comment) Fix #71612 Fix #71709 r? @RalfJung
2 parents d6823ba + c64c776 commit 6318d24

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

src/librustc_mir/interpret/memory.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -400,18 +400,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
400400

401401
// We can still be zero-sized in this branch, in which case we have to
402402
// return `None`.
403-
if size.bytes() == 0 {
404-
// We may be reading from a static.
405-
// In order to ensure that `static FOO: Type = FOO;` causes a cycle error
406-
// instead of magically pulling *any* ZST value from the ether, we need to
407-
// actually access the referenced allocation. The caller is likely
408-
// to short-circuit on `None`, so we trigger the access here to
409-
// make sure it happens.
410-
self.get_raw(ptr.alloc_id)?;
411-
None
412-
} else {
413-
Some(ptr)
414-
}
403+
if size.bytes() == 0 { None } else { Some(ptr) }
415404
}
416405
})
417406
}

src/librustc_mir/interpret/operand.rs

+7
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
240240
{
241241
Some(ptr) => ptr,
242242
None => {
243+
if let Scalar::Ptr(ptr) = mplace.ptr {
244+
// We may be reading from a static.
245+
// In order to ensure that `static FOO: Type = FOO;` causes a cycle error
246+
// instead of magically pulling *any* ZST value from the ether, we need to
247+
// actually access the referenced allocation.
248+
self.memory.get_raw(ptr.alloc_id)?;
249+
}
243250
return Ok(Some(ImmTy {
244251
// zero-sized type
245252
imm: Scalar::zst().into(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// check-pass
2+
3+
// This is a regression test for ICEs from
4+
// https://github.com/rust-lang/rust/issues/71612
5+
// and
6+
// https://github.com/rust-lang/rust/issues/71709
7+
8+
#[derive(Copy, Clone)]
9+
pub struct Glfw;
10+
11+
static mut GLFW: Option<Glfw> = None;
12+
pub fn new() -> Glfw {
13+
unsafe {
14+
if let Some(glfw) = GLFW {
15+
return glfw;
16+
} else {
17+
todo!()
18+
}
19+
};
20+
}
21+
22+
extern "C" {
23+
static _dispatch_queue_attr_concurrent: [u8; 0];
24+
}
25+
26+
static DISPATCH_QUEUE_CONCURRENT: &'static [u8; 0] =
27+
unsafe { &_dispatch_queue_attr_concurrent };
28+
29+
fn main() {
30+
*DISPATCH_QUEUE_CONCURRENT;
31+
new();
32+
}

0 commit comments

Comments
 (0)