Skip to content

Commit 21968aa

Browse files
committed
add test to detect dropped temporary
1 parent aa3bc06 commit 21968aa

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// This should fail even without validation, but some MIR opts mask the error
2+
// compile-flags: -Zmiri-disable-validation -Zmir-opt-level=0
3+
4+
unsafe fn make_ref<'a>(x: *mut i32) -> &'a mut i32 {
5+
&mut *x
6+
}
7+
8+
fn main() {
9+
unsafe {
10+
let x = make_ref(&mut 0); // The temporary storing "0" is deallocated at the ";"!
11+
let val = *x; //~ ERROR dereferenced after this allocation got freed
12+
println!("{}", val);
13+
}
14+
}

0 commit comments

Comments
 (0)