diff --git a/tests/compile-fail/dangling_pointers/stack_temporary.rs b/tests/compile-fail/dangling_pointers/stack_temporary.rs new file mode 100644 index 0000000000..cbd788bbf4 --- /dev/null +++ b/tests/compile-fail/dangling_pointers/stack_temporary.rs @@ -0,0 +1,14 @@ +// This should fail even without validation, but some MIR opts mask the error +// compile-flags: -Zmiri-disable-validation -Zmir-opt-level=0 + +unsafe fn make_ref<'a>(x: *mut i32) -> &'a mut i32 { + &mut *x +} + +fn main() { + unsafe { + let x = make_ref(&mut 0); // The temporary storing "0" is deallocated at the ";"! + let val = *x; //~ ERROR dereferenced after this allocation got freed + println!("{}", val); + } +} diff --git a/tests/compile-fail/storage_dead_dangling.rs b/tests/compile-fail/dangling_pointers/storage_dead_dangling.rs similarity index 100% rename from tests/compile-fail/storage_dead_dangling.rs rename to tests/compile-fail/dangling_pointers/storage_dead_dangling.rs