about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNoa <coolreader18@gmail.com>2024-02-26 11:56:48 -0600
committerNoa <coolreader18@gmail.com>2024-02-26 11:56:48 -0600
commitc7fcf437f1cde4e7f45dcdaf57e80f178d47bd65 (patch)
treeedef1f89b274cf4cbb8cf18cbe87076e2daf3386
parent125b26acf6f3127ecdd344c372691cefe0e9243e (diff)
downloadrust-c7fcf437f1cde4e7f45dcdaf57e80f178d47bd65.tar.gz
rust-c7fcf437f1cde4e7f45dcdaf57e80f178d47bd65.zip
Don't codegen wasm.throw unless with -Zbuild-std
-rw-r--r--library/unwind/src/wasm.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/library/unwind/src/wasm.rs b/library/unwind/src/wasm.rs
index 1de12905f89..b06671bcb83 100644
--- a/library/unwind/src/wasm.rs
+++ b/library/unwind/src/wasm.rs
@@ -40,6 +40,7 @@ pub unsafe fn _Unwind_DeleteException(exception: *mut _Unwind_Exception) {
 }
 
 pub unsafe fn _Unwind_RaiseException(exception: *mut _Unwind_Exception) -> _Unwind_Reason_Code {
+    #[cfg(panic = "unwind")]
     extern "C" {
         /// LLVM lowers this intrinsic to the `throw` instruction.
         // FIXME(coolreader18): move to stdarch
@@ -52,5 +53,13 @@ pub unsafe fn _Unwind_RaiseException(exception: *mut _Unwind_Exception) -> _Unwi
     // via integers, with 0 corresponding to C++ exceptions and 1 to C setjmp()/longjmp().
     // Ideally, we'd be able to choose something unique for Rust, but for now,
     // we pretend to be C++ and implement the Itanium exception-handling ABI.
-    wasm_throw(0, exception.cast())
+    cfg_if::cfg_if! {
+        // for now, unless we're -Zbuild-std with panic=unwind, never codegen a throw.
+        if #[cfg(panic = "unwind")] {
+            wasm_throw(0, exception.cast())
+        } else {
+            let _ = exception;
+            core::arch::wasm32::unreachable()
+        }
+    }
 }