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.
This commit is contained in:
@@ -511,15 +511,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
|
|||||||
err.emit();
|
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(
|
if let Some(features) = check_tied_features(
|
||||||
tcx.sess,
|
tcx.sess,
|
||||||
&codegen_fn_attrs
|
&codegen_fn_attrs
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
//@ compile-flags: -C panic=unwind -Z emscripten-wasm-eh
|
//@ compile-flags: -C panic=unwind -Z emscripten-wasm-eh
|
||||||
|
|
||||||
#![crate_type = "lib"]
|
#![crate_type = "lib"]
|
||||||
#![feature(core_intrinsics)]
|
#![feature(core_intrinsics, wasm_exception_handling_intrinsics)]
|
||||||
|
|
||||||
extern "C-unwind" {
|
extern "C-unwind" {
|
||||||
fn may_panic();
|
fn may_panic();
|
||||||
@@ -57,3 +57,17 @@ pub fn test_rtry() {
|
|||||||
// CHECK: {{.*}} = catchpad within {{.*}} [ptr null]
|
// CHECK: {{.*}} = catchpad within {{.*}} [ptr null]
|
||||||
// CHECK: catchret
|
// 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 []
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user