From 15465a58812f7af4f5d27eb87da191b344d281b5 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 14 Mar 2021 17:10:45 +0100 Subject: [PATCH] don't ICE when we unwind despite panic=abort --- src/shims/panic.rs | 4 +++- tests/compile-fail/panic/unwind_panic_abort.rs | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/compile-fail/panic/unwind_panic_abort.rs diff --git a/src/shims/panic.rs b/src/shims/panic.rs index abc7aa2ad1b..8f06e5276f5 100644 --- a/src/shims/panic.rs +++ b/src/shims/panic.rs @@ -45,7 +45,9 @@ fn handle_miri_start_panic( trace!("miri_start_panic: {:?}", this.frame().instance); // Make sure we only start unwinding when this matches our panic strategy. - assert_eq!(this.tcx.sess.panic_strategy(), PanicStrategy::Unwind); + if this.tcx.sess.panic_strategy() != PanicStrategy::Unwind { + throw_ub_format!("unwinding despite panic=abort"); + } // Get the raw pointer stored in arg[0] (the panic payload). let &[ref payload] = check_arg_count(args)?; diff --git a/tests/compile-fail/panic/unwind_panic_abort.rs b/tests/compile-fail/panic/unwind_panic_abort.rs new file mode 100644 index 00000000000..05284eb770b --- /dev/null +++ b/tests/compile-fail/panic/unwind_panic_abort.rs @@ -0,0 +1,11 @@ +// compile-flags: -Cpanic=abort + +//! Unwinding despite `-C panic=abort` is an error. + +extern "Rust" { + fn miri_start_panic(payload: *mut u8) -> !; +} + +fn main() { + unsafe { miri_start_panic(&mut 0); } //~ ERROR unwinding despite panic=abort +}