Skip to content

Commit b39869b

Browse files
committed
ffi_unwind_calls: treat RustIntrinsic like regular Rust calls
1 parent 8f359be commit b39869b

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

compiler/rustc_mir_transform/src/ffi_unwind_calls.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ use rustc_target::spec::PanicStrategy;
1010

1111
use crate::errors;
1212

13+
/// Some of the functions declard as "may unwind" by `fn_can_unwind` can't actually unwind. In
14+
/// particular, `extern "C"` is still considered as can-unwind on stable, but we need to to consider
15+
/// it cannot-unwind here. So below we check `fn_can_unwind() && abi_can_unwind()` before cincluding
16+
/// that a function call can unwind.
1317
fn abi_can_unwind(abi: Abi) -> bool {
1418
use Abi::*;
1519
match abi {
@@ -33,10 +37,9 @@ fn abi_can_unwind(abi: Abi) -> bool {
3337
| RiscvInterruptS
3438
| CCmseNonSecureCall
3539
| Wasm
36-
| RustIntrinsic
3740
| PlatformIntrinsic
3841
| Unadjusted => false,
39-
Rust | RustCall | RustCold => true,
42+
RustIntrinsic | Rust | RustCall | RustCold => unreachable!(), // these ABIs are already skipped earlier
4043
}
4144
}
4245

@@ -82,14 +85,16 @@ fn has_ffi_unwind_calls(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> bool {
8285
let sig = ty.fn_sig(tcx);
8386

8487
// Rust calls cannot themselves create foreign unwinds.
85-
if let Abi::Rust | Abi::RustCall | Abi::RustCold = sig.abi() {
88+
// We assume this is true for intrinsics as well.
89+
if let Abi::RustIntrinsic | Abi::Rust | Abi::RustCall | Abi::RustCold = sig.abi() {
8690
continue;
8791
};
8892

8993
let fn_def_id = match ty.kind() {
9094
ty::FnPtr(_) => None,
9195
&ty::FnDef(def_id, _) => {
92-
// Rust calls cannot themselves create foreign unwinds.
96+
// Rust calls cannot themselves create foreign unwinds (even if they use a non-Rust ABI).
97+
// So the leak of the foreign unwind into Rust can only be elsewhere, not here.
9398
if !tcx.is_foreign_item(def_id) {
9499
continue;
95100
}

0 commit comments

Comments
 (0)