Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wasm32] Add an intrinsic for the throw instruction #1542

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions crates/core_arch/src/wasm32/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,25 @@ pub use self::memory::*;
pub fn unreachable() -> ! {
crate::intrinsics::abort()
}

extern "C" {
#[link_name = "llvm.wasm.throw"]
fn wasm_throw(tag: i32, ptr: *mut u8) -> !;
}

/// Generates the [`throw`] instruction from the [exception-handling proposal] for WASM.
///
/// This function is unlikely to be stabilized until codegen backends have better support.
///
/// [`throw`]: https://webassembly.github.io/exception-handling/core/syntax/instructions.html#syntax-instr-control
/// [exception-handling proposal]: https://github.com/WebAssembly/exception-handling
// FIXME: wasmtime does not currently support exception-handling, so cannot execute
// a wasm module with the throw instruction in it. once it does, we can
// reenable this attribute.
// #[cfg_attr(test, assert_instr(throw, TAG = 0, ptr = core::ptr::null_mut()))]
#[inline]
#[unstable(feature = "wasm_exception_handling_intrinsics", issue = "122465")]
pub unsafe fn throw<const TAG: i32>(ptr: *mut u8) -> ! {
static_assert!(TAG == 0); // LLVM only supports tag 0 == C++ right now.
wasm_throw(TAG, ptr)
}