Skip to content

Commit 839872f

Browse files
committedOct 18, 2024·
tail_calls: add test ensuring local vars are indeed gone
1 parent 2a2aa27 commit 839872f

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![feature(explicit_tail_calls)]
2+
#![allow(incomplete_features)]
3+
4+
fn g(x: *const i32) {
5+
let _val = unsafe { *x }; //~ERROR: has been freed, so this pointer is dangling
6+
}
7+
8+
fn f(_x: *const i32) {
9+
let local = 0;
10+
let ptr = &local as *const i32;
11+
become g(ptr)
12+
}
13+
14+
fn main() {
15+
f(std::ptr::null());
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
error: Undefined Behavior: memory access failed: ALLOC has been freed, so this pointer is dangling
2+
--> tests/fail/tail_calls/dangling-local-var.rs:LL:CC
3+
|
4+
LL | let _val = unsafe { *x };
5+
| ^^ memory access failed: ALLOC has been freed, so this pointer is dangling
6+
|
7+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9+
help: ALLOC was allocated here:
10+
--> tests/fail/tail_calls/dangling-local-var.rs:LL:CC
11+
|
12+
LL | let local = 0;
13+
| ^^^^^
14+
help: ALLOC was deallocated here:
15+
--> tests/fail/tail_calls/dangling-local-var.rs:LL:CC
16+
|
17+
LL | }
18+
| ^
19+
= note: BACKTRACE (of the first span):
20+
= note: inside `g` at tests/fail/tail_calls/dangling-local-var.rs:LL:CC
21+
note: inside `main`
22+
--> tests/fail/tail_calls/dangling-local-var.rs:LL:CC
23+
|
24+
LL | f(std::ptr::null());
25+
| ^^^^^^^^^^^^^^^^^^^
26+
27+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
28+
29+
error: aborting due to 1 previous error
30+

0 commit comments

Comments
 (0)
Please sign in to comment.