]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/dangling_pointers/dangling_zst_deref.rs
Auto merge of #105457 - GuillaumeGomez:prevent-auto-blanket-impl-retrieval, r=notriddle
[rust.git] / src / tools / miri / tests / fail / dangling_pointers / dangling_zst_deref.rs
1 // Make sure we find these even with many checks disabled.
2 // Some optimizations remove ZST accesses, thus masking this UB.
3 //@compile-flags: -Zmir-opt-level=0 -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation
4
5 fn main() {
6     let p = {
7         let b = Box::new(42);
8         &*b as *const i32 as *const ()
9     };
10     let _x = unsafe { *p }; //~ ERROR: dereferenced after this allocation got freed
11 }