From e06de16a8242ce55b84ad273de25c8d8696a9e4d Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Sat, 19 Nov 2022 23:03:22 +0000 Subject: [PATCH] Add miri tests for terminate terminator --- .../miri/tests/fail/terminate-terminator.rs | 27 +++++++++++++++++++ .../tests/fail/terminate-terminator.stderr | 27 +++++++++++++++++++ ...rminator.rs => unwind-action-terminate.rs} | 0 ....stderr => unwind-action-terminate.stderr} | 8 +++--- 4 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 src/tools/miri/tests/fail/terminate-terminator.rs create mode 100644 src/tools/miri/tests/fail/terminate-terminator.stderr rename src/tools/miri/tests/fail/{abort-terminator.rs => unwind-action-terminate.rs} (100%) rename src/tools/miri/tests/fail/{abort-terminator.stderr => unwind-action-terminate.stderr} (66%) diff --git a/src/tools/miri/tests/fail/terminate-terminator.rs b/src/tools/miri/tests/fail/terminate-terminator.rs new file mode 100644 index 00000000000..f4931659fc8 --- /dev/null +++ b/src/tools/miri/tests/fail/terminate-terminator.rs @@ -0,0 +1,27 @@ +//@compile-flags: -Zmir-opt-level=3 +// Enable MIR inlining to ensure that `TerminatorKind::Terminate` is generated +// instead of just `UnwindAction::Terminate`. + +#![feature(c_unwind)] + +struct Foo; + +impl Drop for Foo { + fn drop(&mut self) {} +} + +#[inline(always)] +fn has_cleanup() { + //~^ ERROR: panic in a function that cannot unwind + // FIXME(nbdd0121): The error should be reported at the call site. + let _f = Foo; + panic!(); +} + +extern "C" fn panic_abort() { + has_cleanup(); +} + +fn main() { + panic_abort(); +} diff --git a/src/tools/miri/tests/fail/terminate-terminator.stderr b/src/tools/miri/tests/fail/terminate-terminator.stderr new file mode 100644 index 00000000000..3befd83007b --- /dev/null +++ b/src/tools/miri/tests/fail/terminate-terminator.stderr @@ -0,0 +1,27 @@ +thread 'main' panicked at 'explicit panic', $DIR/terminate-terminator.rs:LL:CC +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace +error: abnormal termination: panic in a function that cannot unwind + --> $DIR/terminate-terminator.rs:LL:CC + | +LL | / fn has_cleanup() { +LL | | +LL | | // FIXME(nbdd0121): The error should be reported at the call site. +LL | | let _f = Foo; +LL | | panic!(); +LL | | } + | |_^ panic in a function that cannot unwind +... +LL | has_cleanup(); + | ------------- in this inlined function call + | + = note: inside `panic_abort` at $DIR/terminate-terminator.rs:LL:CC +note: inside `main` + --> $DIR/terminate-terminator.rs:LL:CC + | +LL | panic_abort(); + | ^^^^^^^^^^^^^ + +note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace + +error: aborting due to previous error + diff --git a/src/tools/miri/tests/fail/abort-terminator.rs b/src/tools/miri/tests/fail/unwind-action-terminate.rs similarity index 100% rename from src/tools/miri/tests/fail/abort-terminator.rs rename to src/tools/miri/tests/fail/unwind-action-terminate.rs diff --git a/src/tools/miri/tests/fail/abort-terminator.stderr b/src/tools/miri/tests/fail/unwind-action-terminate.stderr similarity index 66% rename from src/tools/miri/tests/fail/abort-terminator.stderr rename to src/tools/miri/tests/fail/unwind-action-terminate.stderr index 966435ef92d..52a1879cb5f 100644 --- a/src/tools/miri/tests/fail/abort-terminator.stderr +++ b/src/tools/miri/tests/fail/unwind-action-terminate.stderr @@ -1,7 +1,7 @@ -thread 'main' panicked at 'explicit panic', $DIR/abort-terminator.rs:LL:CC +thread 'main' panicked at 'explicit panic', $DIR/unwind-action-terminate.rs:LL:CC note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace error: abnormal termination: panic in a function that cannot unwind - --> $DIR/abort-terminator.rs:LL:CC + --> $DIR/unwind-action-terminate.rs:LL:CC | LL | / extern "C" fn panic_abort() { LL | | @@ -9,9 +9,9 @@ LL | | panic!() LL | | } | |_^ panic in a function that cannot unwind | - = note: inside `panic_abort` at $DIR/abort-terminator.rs:LL:CC + = note: inside `panic_abort` at $DIR/unwind-action-terminate.rs:LL:CC note: inside `main` - --> $DIR/abort-terminator.rs:LL:CC + --> $DIR/unwind-action-terminate.rs:LL:CC | LL | panic_abort(); | ^^^^^^^^^^^^^