Skip to content

Commit

Permalink
Add miri tests for terminate terminator
Browse files Browse the repository at this point in the history
  • Loading branch information
nbdd0121 committed Apr 6, 2023
1 parent 2a9d710 commit e06de16
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
27 changes: 27 additions & 0 deletions src/tools/miri/tests/fail/terminate-terminator.rs
Original file line number Diff line number Diff line change
@@ -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();
}
27 changes: 27 additions & 0 deletions src/tools/miri/tests/fail/terminate-terminator.stderr
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
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 | |
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();
| ^^^^^^^^^^^^^
Expand Down

0 comments on commit e06de16

Please sign in to comment.