1 // Some optimizations remove ZST accesses, thus masking this UB.
2 //@compile-flags: -Zmir-opt-level=0
5 // Not using the () type here, as writes of that type do not even have MIR generated.
6 // Also not assigning directly as that's array initialization, not assignment.
7 let zst_val = [1u8; 0];
9 // make sure ZST accesses are checked against being "truly" dangling pointers
10 // (into deallocated allocations).
11 let mut x_box = Box::new(1u8);
12 let x = &mut *x_box as *mut _ as *mut [u8; 0];
14 unsafe { *x = zst_val }; //~ ERROR: dereferenced after this allocation got freed