Don't codegen wasm.throw unless with -Zbuild-std · rust-lang/rust@c7fcf43 (original) (raw)

Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@ pub unsafe fn _Unwind_DeleteException(exception: *mut _Unwind_Exception) {
40 40 }
41 41
42 42 pub unsafe fn _Unwind_RaiseException(exception: *mut _Unwind_Exception) -> _Unwind_Reason_Code {
43 +#[cfg(panic = "unwind")]
43 44 extern "C" {
44 45 /// LLVM lowers this intrinsic to the `throw` instruction.
45 46 // FIXME(coolreader18): move to stdarch
@@ -52,5 +53,13 @@ pub unsafe fn _Unwind_RaiseException(exception: *mut _Unwind_Exception) -> _Unwi
52 53 // via integers, with 0 corresponding to C++ exceptions and 1 to C setjmp()/longjmp().
53 54 // Ideally, we'd be able to choose something unique for Rust, but for now,
54 55 // 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 +}
56 65 }