Skip to content

Don't special-case llvm.* as nounwind #144225

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

Merged
merged 2 commits into from
Jul 28, 2025
Merged
Show file tree
Hide file tree
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
9 changes: 0 additions & 9 deletions compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,15 +511,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
err.emit();
}

// Any linkage to LLVM intrinsics for now forcibly marks them all as never
// unwinds since LLVM sometimes can't handle codegen which `invoke`s
// intrinsic functions.
if let Some(name) = &codegen_fn_attrs.link_name
&& name.as_str().starts_with("llvm.")
{
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NEVER_UNWIND;
}

if let Some(features) = check_tied_features(
tcx.sess,
&codegen_fn_attrs
Expand Down
10 changes: 10 additions & 0 deletions library/stdarch/crates/core_arch/src/wasm32/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ unsafe extern "C-unwind" {
// #[cfg_attr(test, assert_instr(throw, TAG = 0, ptr = core::ptr::null_mut()))]
#[inline]
#[unstable(feature = "wasm_exception_handling_intrinsics", issue = "122465")]
// FIXME: Since this instruction unwinds, `core` built with `-C panic=unwind`
// cannot be linked with `-C panic=abort` programs. But that's not
// entirely supported anyway, because runtimes without EH support won't
// be able to handle `try` blocks in `-C panic=unwind` crates either.
// We ship `-C panic=abort` `core`, so this doesn't affect users
// directly. Resolving this will likely require patching out both `try`
// and `throw` instructions, at which point we can look into whitelisting
// this function in the compiler to allow linking.
// See https://github.com/rust-lang/rust/issues/118168.
#[allow(ffi_unwind_calls)]
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)
Expand Down
16 changes: 15 additions & 1 deletion tests/codegen-llvm/wasm_exceptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//@ compile-flags: -C panic=unwind -Z emscripten-wasm-eh

#![crate_type = "lib"]
#![feature(core_intrinsics)]
#![feature(core_intrinsics, wasm_exception_handling_intrinsics)]

extern "C-unwind" {
fn may_panic();
Expand Down Expand Up @@ -57,3 +57,17 @@ pub fn test_rtry() {
// CHECK: {{.*}} = catchpad within {{.*}} [ptr null]
// CHECK: catchret
}

// Make sure the intrinsic is not inferred as nounwind. This is a regression test for #132416.
// CHECK-LABEL: @test_intrinsic() {{.*}} @__gxx_wasm_personality_v0
#[no_mangle]
pub fn test_intrinsic() {
let _log_on_drop = LogOnDrop;
unsafe {
core::arch::wasm32::throw::<0>(core::ptr::null_mut());
}

// CHECK-NOT: call
// CHECK: invoke void @llvm.wasm.throw(i32 noundef 0, ptr noundef null)
// CHECK: %cleanuppad = cleanuppad within none []
}
Loading