Skip to content

Commit

Permalink
Mark all functions defined in compiler-builtins as nounwind
Browse files Browse the repository at this point in the history
  • Loading branch information
nbdd0121 committed Feb 25, 2024
1 parent 8c0b1fc commit 77dcc65
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 77dcc65

Please sign in to comment.