@@ -40,29 +40,25 @@ 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" ) ]
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
-
51
43
// The wasm `throw` instruction takes a "tag", which differentiates certain
52
44
// types of exceptions from others. LLVM currently just identifies these
53
45
// via integers, with 0 corresponding to C++ exceptions and 1 to C setjmp()/longjmp().
54
46
// Ideally, we'd be able to choose something unique for Rust, but for now,
55
47
// we pretend to be C++ and implement the Itanium exception-handling ABI.
56
48
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.
58
54
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( ) )
60
59
} else {
61
60
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( )
66
62
}
67
63
}
68
64
}
0 commit comments