Skip to content

Commit 79dafdd

Browse files
committed
Auto merge of rust-lang#121605 - nbdd0121:builtin, r=Amanieu
Mark all functions defined in compiler-builtins as nounwind Treat functions in compiler-builtins as nounwind. Suggested in rust-lang/compiler-builtins#578 (comment). A prerequisite for rust-lang#116088 r? `@Amanieu` cc `@RalfJung`
2 parents 0250ef2 + 77dcc65 commit 79dafdd

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

compiler/rustc_middle/src/ty/layout.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,21 @@ pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: SpecAbi) ->
11801180
return false;
11811181
}
11821182
}
1183+
1184+
// Functions in compiler builtins can never unwind.
1185+
//
1186+
// The `compiler-builtins` crate exports a bunch of LLVM intrinsics which are defined
1187+
// with the C ABI, so it must not unwind. If such functions call into unwindable
1188+
// functions, rustc will inject unwind guards to prevent unwind leaking out. This is
1189+
// normally okay, but for `compiler-builtins` crate it has the additional requirement to
1190+
// not call into libcore, so we *must not* generate such guards. One way to do it is to
1191+
// ensure those exported functions never call into unwindable functions, so we make
1192+
// every single function defined in compiler builtins nounwind.
1193+
//
1194+
// See rust-lang/compiler-builtins#578 for context.
1195+
if tcx.is_compiler_builtins(did.krate) && !tcx.is_foreign_item(did) {
1196+
return false;
1197+
}
11831198
}
11841199

11851200
// Otherwise if this isn't special then unwinding is generally determined by

0 commit comments

Comments
 (0)