Skip to content

Commit

Permalink
tail_calls: add test ensuring local vars are indeed gone
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Oct 18, 2024
1 parent 2a2aa27 commit 839872f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/fail/tail_calls/dangling-local-var.rs
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());
}
30 changes: 30 additions & 0 deletions tests/fail/tail_calls/dangling-local-var.stderr
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

0 comments on commit 839872f

Please sign in to comment.