Skip to content

Commit c7fcf43

Browse files
committed
Don't codegen wasm.throw unless with -Zbuild-std
1 parent 125b26a commit c7fcf43

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

library/unwind/src/wasm.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub unsafe fn _Unwind_DeleteException(exception: *mut _Unwind_Exception) {
4040
}
4141

4242
pub unsafe fn _Unwind_RaiseException(exception: *mut _Unwind_Exception) -> _Unwind_Reason_Code {
43+
#[cfg(panic = "unwind")]
4344
extern "C" {
4445
/// LLVM lowers this intrinsic to the `throw` instruction.
4546
// FIXME(coolreader18): move to stdarch
@@ -52,5 +53,13 @@ pub unsafe fn _Unwind_RaiseException(exception: *mut _Unwind_Exception) -> _Unwi
5253
// via integers, with 0 corresponding to C++ exceptions and 1 to C setjmp()/longjmp().
5354
// Ideally, we'd be able to choose something unique for Rust, but for now,
5455
// we pretend to be C++ and implement the Itanium exception-handling ABI.
55-
wasm_throw(0, exception.cast())
56+
cfg_if::cfg_if! {
57+
// for now, unless we're -Zbuild-std with panic=unwind, never codegen a throw.
58+
if #[cfg(panic = "unwind")] {
59+
wasm_throw(0, exception.cast())
60+
} else {
61+
let _ = exception;
62+
core::arch::wasm32::unreachable()
63+
}
64+
}
5665
}

0 commit comments

Comments
 (0)