rust/tests/fail/dangling_pointers/maybe_null_pointer_deref_zst.rs

9 lines
322 B
Rust
Raw Normal View History

2021-03-25 06:44:30 -05:00
// Some optimizations remove ZST accesses, thus masking this UB.
2022-07-08 11:08:32 -05:00
//@compile-flags: -Zmir-opt-level=0
2021-03-25 06:44:30 -05:00
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
}