rust/tests/compile-fail/dangling_pointers/maybe_null_pointer_deref_zst.rs
2021-07-16 10:10:12 +02:00

9 lines
321 B
Rust

// Some optimizations remove ZST accesses, thus masking this UB.
// compile-flags: -Zmir-opt-level=0
fn main() {
// This pointer *could* be NULL so we cannot load from it, not even at ZST
let ptr = (&0u8 as *const u8).wrapping_sub(0x800) as *const ();
let _x: () = unsafe { *ptr }; //~ ERROR out-of-bounds
}