diff options
| author | Ralf Jung <post@ralfj.de> | 2024-10-18 16:08:52 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2024-10-18 16:08:52 +0200 |
| commit | 2775f3962abe4060b4f11bfb5d2b822fbaf18035 (patch) | |
| tree | 513a953eb760478114aa84f3f3e5167c1075a9e6 /src | |
| parent | dd81b8c074612732bae14eac9c7d652e43b629b5 (diff) | |
| download | rust-2775f3962abe4060b4f11bfb5d2b822fbaf18035.tar.gz rust-2775f3962abe4060b4f11bfb5d2b822fbaf18035.zip | |
tail_calls: add test ensuring local vars are indeed gone
Diffstat (limited to 'src')
| -rw-r--r-- | src/tools/miri/tests/fail/tail_calls/dangling-local-var.rs | 16 | ||||
| -rw-r--r-- | src/tools/miri/tests/fail/tail_calls/dangling-local-var.stderr | 30 |
2 files changed, 46 insertions, 0 deletions
diff --git a/src/tools/miri/tests/fail/tail_calls/dangling-local-var.rs b/src/tools/miri/tests/fail/tail_calls/dangling-local-var.rs new file mode 100644 index 00000000000..b69f7ee9dff --- /dev/null +++ b/src/tools/miri/tests/fail/tail_calls/dangling-local-var.rs @@ -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()); +} diff --git a/src/tools/miri/tests/fail/tail_calls/dangling-local-var.stderr b/src/tools/miri/tests/fail/tail_calls/dangling-local-var.stderr new file mode 100644 index 00000000000..6acd69ab3f8 --- /dev/null +++ b/src/tools/miri/tests/fail/tail_calls/dangling-local-var.stderr @@ -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 + |
