Skip to content

Commit d216dbd

Browse files
coolreader18Amanieu
authored andcommitted
[wasm32] Add an intrinsic for the throw instruction
1 parent 166ef7b commit d216dbd

File tree

1 file changed

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

1 file changed

+22
-0
lines changed

crates/core_arch/src/wasm32/mod.rs

+22
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,25 @@ 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+
// FIXME: wasmtime does not currently support exception-handling, so cannot execute
47+
// a wasm module with the throw instruction in it. once it does, we can
48+
// reenable this attribute.
49+
// #[cfg_attr(test, assert_instr(throw, TAG = 0, ptr = core::ptr::null_mut()))]
50+
#[inline]
51+
#[unstable(feature = "wasm_exception_handling_intrinsics", issue = "122465")]
52+
pub unsafe fn throw<const TAG: i32>(ptr: *mut u8) -> ! {
53+
static_assert!(TAG == 0); // LLVM only supports tag 0 == C++ right now.
54+
wasm_throw(TAG, ptr)
55+
}

0 commit comments

Comments
 (0)