diff --git a/tests/fail/dangling_pointers/dangling_pointer_project_underscore_match.rs b/tests/fail/dangling_pointers/dangling_pointer_project_underscore_match.rs new file mode 100644 index 0000000000..8541da8485 --- /dev/null +++ b/tests/fail/dangling_pointers/dangling_pointer_project_underscore_match.rs @@ -0,0 +1,15 @@ +// Make sure we find these even with many checks disabled. +//@compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation + +fn main() { + let p = { + let b = Box::new(42); + &*b as *const i32 as *const (u8, u8, u8, u8) + }; + unsafe { + match (*p).1 { + //~^ ERROR: out-of-bounds pointer arithmetic + _ => {} + } + } +} diff --git a/tests/fail/dangling_pointers/dangling_pointer_project_underscore_match.stderr b/tests/fail/dangling_pointers/dangling_pointer_project_underscore_match.stderr new file mode 100644 index 0000000000..625a7b5f60 --- /dev/null +++ b/tests/fail/dangling_pointers/dangling_pointer_project_underscore_match.stderr @@ -0,0 +1,25 @@ +error: Undefined Behavior: out-of-bounds pointer arithmetic: ALLOC has been freed, so this pointer is dangling + --> $DIR/dangling_pointer_project_underscore_match.rs:LL:CC + | +LL | match (*p).1 { + | ^^^^^^ out-of-bounds pointer arithmetic: 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: + --> $DIR/dangling_pointer_project_underscore_match.rs:LL:CC + | +LL | let b = Box::new(42); + | ^^^^^^^^^^^^ +help: ALLOC was deallocated here: + --> $DIR/dangling_pointer_project_underscore_match.rs:LL:CC + | +LL | }; + | ^ + = note: BACKTRACE (of the first span): + = note: inside `main` at $DIR/dangling_pointer_project_underscore_match.rs:LL:CC + +note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace + +error: aborting due to previous error +