From c9ff02f549cf30cf9f3007b34fde89dcf0f46ac2 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 14 Mar 2021 17:03:20 +0100 Subject: [PATCH] ensure we catch incorrectly unwinding calls --- tests/compile-fail/panic/bad_unwind.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/compile-fail/panic/bad_unwind.rs diff --git a/tests/compile-fail/panic/bad_unwind.rs b/tests/compile-fail/panic/bad_unwind.rs new file mode 100644 index 000000000000..fde2c19af07d --- /dev/null +++ b/tests/compile-fail/panic/bad_unwind.rs @@ -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(); +}