about summary refs log tree commit diff
path: root/src/tools/miri/tests/fail/panic/bad_unwind.rs
blob: 5370485b2a6230464091e8b5837ee2d53c0ad960 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//! Unwinding when the caller ABI is "C" (without "-unwind") is UB.
// The opposite version (callee does not allow unwinding) is impossible to
// even write: MIR validation catches functions that have `UnwindContinue` but
// are not allowed to unwind.

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();
    //~^ ERROR: unwinding past a stack frame that does not allow unwinding
}