Skip to content

Commit a798792

Browse files
committed
Auto merge of #1744 - rust-lang:bad-unwind, r=RalfJung
ensure we catch incorrectly unwinding calls Fixes #1740
2 parents ae96420 + 15465a5 commit a798792

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

src/shims/panic.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
4545

4646
trace!("miri_start_panic: {:?}", this.frame().instance);
4747
// Make sure we only start unwinding when this matches our panic strategy.
48-
assert_eq!(this.tcx.sess.panic_strategy(), PanicStrategy::Unwind);
48+
if this.tcx.sess.panic_strategy() != PanicStrategy::Unwind {
49+
throw_ub_format!("unwinding despite panic=abort");
50+
}
4951

5052
// Get the raw pointer stored in arg[0] (the panic payload).
5153
let &[ref payload] = check_arg_count(args)?;
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// error-pattern: calling a function with ABI C-unwind using caller ABI C
2+
#![feature(c_unwind)]
3+
4+
//! Unwinding when the caller ABI is "C" (without "-unwind") is UB.
5+
//! Currently we detect the ABI mismatch; we could probably allow such calls in principle one day
6+
//! but then we have to detect the unexpected unwinding.
7+
8+
extern "C-unwind" fn unwind() {
9+
panic!();
10+
}
11+
12+
fn main() {
13+
let unwind: extern "C-unwind" fn() = unwind;
14+
let unwind: extern "C" fn() = unsafe { std::mem::transmute(unwind) };
15+
std::panic::catch_unwind(|| unwind()).unwrap_err();
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// compile-flags: -Cpanic=abort
2+
3+
//! Unwinding despite `-C panic=abort` is an error.
4+
5+
extern "Rust" {
6+
fn miri_start_panic(payload: *mut u8) -> !;
7+
}
8+
9+
fn main() {
10+
unsafe { miri_start_panic(&mut 0); } //~ ERROR unwinding despite panic=abort
11+
}

0 commit comments

Comments
 (0)