Skip to content

Commit

Permalink
Auto merge of rust-lang#121605 - nbdd0121:builtin, r=Amanieu
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
bors committed Feb 26, 2024
2 parents 0250ef2 + 77dcc65 commit 79dafdd
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,21 @@ pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: SpecAbi) ->
return false;
}
}

// Functions in compiler builtins can never unwind.
//
// The `compiler-builtins` crate exports a bunch of LLVM intrinsics which are defined
// with the C ABI, so it must not unwind. If such functions call into unwindable
// functions, rustc will inject unwind guards to prevent unwind leaking out. This is
// normally okay, but for `compiler-builtins` crate it has the additional requirement to
// not call into libcore, so we *must not* generate such guards. One way to do it is to
// ensure those exported functions never call into unwindable functions, so we make
// every single function defined in compiler builtins nounwind.
//
// See rust-lang/compiler-builtins#578 for context.
if tcx.is_compiler_builtins(did.krate) && !tcx.is_foreign_item(did) {
return false;
}
}

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

0 comments on commit 79dafdd

Please sign in to comment.