-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tail_calls: add test ensuring local vars are indeed gone
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|