Skip to content

Commit 78126eb

Browse files
committed
[wasm32] Add an intrinsic for the throw instruction
1 parent a9887d1 commit 78126eb

File tree

1 file changed

+19
-0
lines changed
  • crates/core_arch/src/wasm32

1 file changed

+19
-0
lines changed

crates/core_arch/src/wasm32/mod.rs

+19
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,22 @@ pub use self::memory::*;
3131
pub fn unreachable() -> ! {
3232
crate::intrinsics::abort()
3333
}
34+
35+
extern "C" {
36+
#[link_name = "llvm.wasm.throw"]
37+
fn wasm_throw(tag: i32, ptr: *mut u8) -> !;
38+
}
39+
40+
/// Generates the [`throw`] instruction from the [exception-handling proposal] for WASM.
41+
///
42+
/// This function is unlikely to be stabilized until codegen backends have better support.
43+
///
44+
/// [`throw`]: https://webassembly.github.io/exception-handling/core/syntax/instructions.html#syntax-instr-control
45+
/// [exception-handling proposal]: https://github.com/WebAssembly/exception-handling
46+
#[cfg_attr(test, assert_instr(unreachable))]
47+
#[inline]
48+
#[unstable(feature = "wasm_exception_handling_intrinsic", issue = "none")]
49+
pub unsafe fn throw<const TAG: i32>(ptr: *mut u8) -> ! {
50+
static_assert!(TAG == 0); // LLVM only supports tag 0 == C++ right now.
51+
wasm_throw(TAG, ptr)
52+
}

0 commit comments

Comments
 (0)