Auto merge of #3979 - RalfJung:tail-call-drops-locals, r=RalfJung
tail_calls: add test ensuring local vars are indeed gone Ensure that local variables get deallocated before the callee gets tail-called.
This commit is contained in:
commit
3386ae21cc
16
src/tools/miri/tests/fail/tail_calls/dangling-local-var.rs
Normal file
16
src/tools/miri/tests/fail/tail_calls/dangling-local-var.rs
Normal file
@ -0,0 +1,16 @@
|
||||
#![feature(explicit_tail_calls)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
fn g(x: *const i32) {
|
||||
let _val = unsafe { *x }; //~ERROR: has been freed, so this pointer is dangling
|
||||
}
|
||||
|
||||
fn f(_x: *const i32) {
|
||||
let local = 0;
|
||||
let ptr = &local as *const i32;
|
||||
become g(ptr)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
f(std::ptr::null());
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
error: Undefined Behavior: memory access failed: ALLOC has been freed, so this pointer is dangling
|
||||
--> tests/fail/tail_calls/dangling-local-var.rs:LL:CC
|
||||
|
|
||||
LL | let _val = unsafe { *x };
|
||||
| ^^ memory access failed: ALLOC has been freed, so this pointer is dangling
|
||||
|
|
||||
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
|
||||
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
|
||||
help: ALLOC was allocated here:
|
||||
--> tests/fail/tail_calls/dangling-local-var.rs:LL:CC
|
||||
|
|
||||
LL | let local = 0;
|
||||
| ^^^^^
|
||||
help: ALLOC was deallocated here:
|
||||
--> tests/fail/tail_calls/dangling-local-var.rs:LL:CC
|
||||
|
|
||||
LL | }
|
||||
| ^
|
||||
= note: BACKTRACE (of the first span):
|
||||
= note: inside `g` at tests/fail/tail_calls/dangling-local-var.rs:LL:CC
|
||||
note: inside `main`
|
||||
--> tests/fail/tail_calls/dangling-local-var.rs:LL:CC
|
||||
|
|
||||
LL | f(std::ptr::null());
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
Loading…
x
Reference in New Issue
Block a user