Skip to content

tail_calls: add test ensuring local vars are indeed gone #3979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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