Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2b5e239

Browse files
committed
Auto merge of #144225 - purplesyringa:unwinding-intrinsics, r=nikic
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. Closes #132416. `@rustbot` label +T-compiler +A-panic
2 parents f8e355c + 17519ae commit 2b5e239

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-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

‎library/stdarch/crates/core_arch/src/wasm32/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,16 @@ unsafe extern "C-unwind" {
191191
// #[cfg_attr(test, assert_instr(throw, TAG = 0, ptr = core::ptr::null_mut()))]
192192
#[inline]
193193
#[unstable(feature = "wasm_exception_handling_intrinsics", issue = "122465")]
194+
// FIXME: Since this instruction unwinds, `core` built with `-C panic=unwind`
195+
// cannot be linked with `-C panic=abort` programs. But that's not
196+
// entirely supported anyway, because runtimes without EH support won't
197+
// be able to handle `try` blocks in `-C panic=unwind` crates either.
198+
// We ship `-C panic=abort` `core`, so this doesn't affect users
199+
// directly. Resolving this will likely require patching out both `try`
200+
// and `throw` instructions, at which point we can look into whitelisting
201+
// this function in the compiler to allow linking.
202+
// See https://github.com/rust-lang/rust/issues/118168.
203+
#[allow(ffi_unwind_calls)]
194204
pub unsafe fn throw<const TAG: i32>(ptr: *mut u8) -> ! {
195205
static_assert!(TAG == 0); // LLVM only supports tag 0 == C++ right now.
196206
wasm_throw(TAG, ptr)

‎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)

AltStyle によって変換されたページ (->オリジナル) /