Skip to content

Commit a29f86b

Browse files
committed
make sure '&raw *' on a dangling raw ptr is UB
1 parent 5961977 commit a29f86b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Make sure we find these even with many checks disabled.
2+
// compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation
3+
#![feature(raw_ref_macros)]
4+
use std::ptr;
5+
6+
fn main() {
7+
let p = {
8+
let b = Box::new(42);
9+
&*b as *const i32
10+
};
11+
let x = unsafe { ptr::raw_const!(*p) }; //~ ERROR dereferenced after this allocation got freed
12+
panic!("this should never print: {:?}", x);
13+
}

0 commit comments

Comments
 (0)