Skip to content

Commit ed11a39

Browse files
committed
Don't special-case llvm.* as nounwind
Certain LLVM intrinsics, such as `llvm.wasm.throw`, can unwind. Marking them as nounwind causes us to skip cleanup of locals and optimize out `catch_unwind` under inlining or when `llvm.wasm.throw` is used directly by user code. The motivation for forcibly marking llvm.* as nounwind is no longer present: most intrinsics are linked as `extern "C"` or other non-unwinding ABIs, so we won't codegen `invoke` for them anyway.
1 parent a7a1618 commit ed11a39

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -511,15 +511,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
511511
err.emit();
512512
}
513513

514-
// Any linkage to LLVM intrinsics for now forcibly marks them all as never
515-
// unwinds since LLVM sometimes can't handle codegen which `invoke`s
516-
// intrinsic functions.
517-
if let Some(name) = &codegen_fn_attrs.link_name
518-
&& name.as_str().starts_with("llvm.")
519-
{
520-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NEVER_UNWIND;
521-
}
522-
523514
if let Some(features) = check_tied_features(
524515
tcx.sess,
525516
&codegen_fn_attrs

tests/codegen-llvm/wasm_exceptions.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//@ compile-flags: -C panic=unwind -Z emscripten-wasm-eh
33

44
#![crate_type = "lib"]
5-
#![feature(core_intrinsics)]
5+
#![feature(core_intrinsics, wasm_exception_handling_intrinsics)]
66

77
extern "C-unwind" {
88
fn may_panic();
@@ -57,3 +57,17 @@ pub fn test_rtry() {
5757
// CHECK: {{.*}} = catchpad within {{.*}} [ptr null]
5858
// CHECK: catchret
5959
}
60+
61+
// Make sure the intrinsic is not inferred as nounwind. This is a regression test for #132416.
62+
// CHECK-LABEL: @test_intrinsic() {{.*}} @__gxx_wasm_personality_v0
63+
#[no_mangle]
64+
pub fn test_intrinsic() {
65+
let _log_on_drop = LogOnDrop;
66+
unsafe {
67+
core::arch::wasm32::throw::<0>(core::ptr::null_mut());
68+
}
69+
70+
// CHECK-NOT: call
71+
// CHECK: invoke void @llvm.wasm.throw(i32 noundef 0, ptr noundef null)
72+
// CHECK: %cleanuppad = cleanuppad within none []
73+
}

0 commit comments

Comments
 (0)