@@ -10,6 +10,10 @@ use rustc_target::spec::PanicStrategy;
10
10
11
11
use crate :: errors;
12
12
13
+ /// Some of the functions declared 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 concluding
16
+ /// that a function call can unwind.
13
17
fn abi_can_unwind ( abi : Abi ) -> bool {
14
18
use Abi :: * ;
15
19
match abi {
@@ -33,9 +37,8 @@ fn abi_can_unwind(abi: Abi) -> bool {
33
37
| RiscvInterruptS
34
38
| CCmseNonSecureCall
35
39
| Wasm
36
- | RustIntrinsic
37
40
| Unadjusted => false ,
38
- Rust | RustCall | RustCold => true ,
41
+ RustIntrinsic | Rust | RustCall | RustCold => unreachable ! ( ) , // these ABIs are already skipped earlier
39
42
}
40
43
}
41
44
@@ -81,14 +84,16 @@ fn has_ffi_unwind_calls(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> bool {
81
84
let sig = ty. fn_sig ( tcx) ;
82
85
83
86
// Rust calls cannot themselves create foreign unwinds.
84
- if let Abi :: Rust | Abi :: RustCall | Abi :: RustCold = sig. abi ( ) {
87
+ // We assume this is true for intrinsics as well.
88
+ if let Abi :: RustIntrinsic | Abi :: Rust | Abi :: RustCall | Abi :: RustCold = sig. abi ( ) {
85
89
continue ;
86
90
} ;
87
91
88
92
let fn_def_id = match ty. kind ( ) {
89
93
ty:: FnPtr ( _) => None ,
90
94
& ty:: FnDef ( def_id, _) => {
91
- // Rust calls cannot themselves create foreign unwinds.
95
+ // Rust calls cannot themselves create foreign unwinds (even if they use a non-Rust ABI).
96
+ // So the leak of the foreign unwind into Rust can only be elsewhere, not here.
92
97
if !tcx. is_foreign_item ( def_id) {
93
98
continue ;
94
99
}
0 commit comments