@@ -40,29 +40,25 @@ pub unsafe fn _Unwind_DeleteException(exception: *mut _Unwind_Exception) {
4040}
4141
4242pub unsafe fn _Unwind_RaiseException ( exception : * mut _Unwind_Exception ) -> _Unwind_Reason_Code {
43- #[ cfg( panic = "unwind" ) ]
44- extern "C" {
45- /// LLVM lowers this intrinsic to the `throw` instruction.
46- // FIXME(coolreader18): move to stdarch
47- #[ link_name = "llvm.wasm.throw" ]
48- fn wasm_throw ( tag : i32 , ptr : * mut u8 ) -> !;
49- }
50-
5143 // The wasm `throw` instruction takes a "tag", which differentiates certain
5244 // types of exceptions from others. LLVM currently just identifies these
5345 // via integers, with 0 corresponding to C++ exceptions and 1 to C setjmp()/longjmp().
5446 // Ideally, we'd be able to choose something unique for Rust, but for now,
5547 // we pretend to be C++ and implement the Itanium exception-handling ABI.
5648 cfg_if:: cfg_if! {
57- // for now, unless we're -Zbuild-std with panic=unwind, never codegen a throw.
49+ // panic=abort is default for wasm targets. Because an unknown instruction is a load-time
50+ // error on wasm, instead of a runtime error like on traditional architectures, we never
51+ // want to codegen a `throw` instruction, as that would break users using runtimes that
52+ // don't yet support exceptions. The only time this first branch would be selected is if
53+ // the user explicitly opts in to wasm exceptions, via -Zbuild-std with -Cpanic=unwind.
5854 if #[ cfg( panic = "unwind" ) ] {
59- wasm_throw( 0 , exception. cast( ) )
55+ // corresponds with llvm::WebAssembly::Tag::CPP_EXCEPTION
56+ // in llvm-project/llvm/include/llvm/CodeGen/WasmEHFuncInfo.h
57+ const CPP_EXCEPTION_TAG : i32 = 0 ;
58+ core:: arch:: wasm:: throw:: <CPP_EXCEPTION_TAG >( exception. cast( ) )
6059 } else {
6160 let _ = exception;
62- #[ cfg( target_arch = "wasm32" ) ]
63- core:: arch:: wasm32:: unreachable( ) ;
64- #[ cfg( target_arch = "wasm64" ) ]
65- core:: arch:: wasm64:: unreachable( ) ;
61+ core:: arch:: wasm:: unreachable( )
6662 }
6763 }
6864}
0 commit comments