Auto merge of #1744 - rust-lang:bad-unwind, r=RalfJung

ensure we catch incorrectly unwinding calls

Fixes https://github.com/rust-lang/miri/issues/1740
This commit is contained in:
bors 2021-03-14 16:11:21 +00:00
commit a798792f1e
3 changed files with 30 additions and 1 deletions

View file

@ -45,7 +45,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
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)?;

View file

@ -0,0 +1,16 @@
// error-pattern: calling a function with ABI C-unwind using caller ABI C
#![feature(c_unwind)]
//! Unwinding when the caller ABI is "C" (without "-unwind") is UB.
//! Currently we detect the ABI mismatch; we could probably allow such calls in principle one day
//! but then we have to detect the unexpected unwinding.
extern "C-unwind" fn unwind() {
panic!();
}
fn main() {
let unwind: extern "C-unwind" fn() = unwind;
let unwind: extern "C" fn() = unsafe { std::mem::transmute(unwind) };
std::panic::catch_unwind(|| unwind()).unwrap_err();
}

View file

@ -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
}