@@ -10,13 +10,10 @@ use rustc_hir::def_id::{DefId, LOCAL_CRATE};
1010use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
1111use rustc_middle:: ty:: layout:: HasTyCtxt ;
1212use rustc_middle:: ty:: query:: Providers ;
13- use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
13+ use rustc_middle:: ty:: { self , TyCtxt } ;
1414use rustc_session:: config:: { OptLevel , Sanitizer } ;
1515use rustc_session:: Session ;
16- use rustc_target:: abi:: call:: Conv ;
17- use rustc_target:: spec:: PanicStrategy ;
1816
19- use crate :: abi:: FnAbi ;
2017use crate :: attributes;
2118use crate :: llvm:: AttributePlace :: Function ;
2219use crate :: llvm:: { self , Attribute } ;
@@ -77,12 +74,6 @@ pub fn emit_uwtable(val: &'ll Value, emit: bool) {
7774 Attribute :: UWTable . toggle_llfn ( Function , val, emit) ;
7875}
7976
80- /// Tell LLVM whether the function can or cannot unwind.
81- #[ inline]
82- fn unwind ( val : & ' ll Value , can_unwind : bool ) {
83- Attribute :: NoUnwind . toggle_llfn ( Function , val, !can_unwind) ;
84- }
85-
8677/// Tell LLVM if this function should be 'naked', i.e., skip the epilogue and prologue.
8778#[ inline]
8879fn naked ( val : & ' ll Value , is_naked : bool ) {
@@ -246,12 +237,7 @@ pub(crate) fn default_optimisation_attrs(sess: &Session, llfn: &'ll Value) {
246237
247238/// Composite function which sets LLVM attributes for function depending on its AST (`#[attribute]`)
248239/// attributes.
249- pub fn from_fn_attrs (
250- cx : & CodegenCx < ' ll , ' tcx > ,
251- llfn : & ' ll Value ,
252- instance : ty:: Instance < ' tcx > ,
253- fn_abi : & FnAbi < ' tcx , Ty < ' tcx > > ,
254- ) {
240+ pub fn from_fn_attrs ( cx : & CodegenCx < ' ll , ' tcx > , llfn : & ' ll Value , instance : ty:: Instance < ' tcx > ) {
255241 let codegen_fn_attrs = cx. tcx . codegen_fn_attrs ( instance. def_id ( ) ) ;
256242
257243 match codegen_fn_attrs. optimize {
@@ -315,46 +301,6 @@ pub fn from_fn_attrs(
315301 }
316302 sanitize ( cx, codegen_fn_attrs. flags , llfn) ;
317303
318- unwind (
319- llfn,
320- if cx. tcx . sess . panic_strategy ( ) != PanicStrategy :: Unwind {
321- // In panic=abort mode we assume nothing can unwind anywhere, so
322- // optimize based on this!
323- false
324- } else if codegen_fn_attrs. flags . contains ( CodegenFnAttrFlags :: UNWIND ) {
325- // If a specific #[unwind] attribute is present, use that.
326- true
327- } else if codegen_fn_attrs. flags . contains ( CodegenFnAttrFlags :: RUSTC_ALLOCATOR_NOUNWIND ) {
328- // Special attribute for allocator functions, which can't unwind.
329- false
330- } else {
331- if fn_abi. conv == Conv :: Rust {
332- // Any Rust method (or `extern "Rust" fn` or `extern
333- // "rust-call" fn`) is explicitly allowed to unwind
334- // (unless it has no-unwind attribute, handled above).
335- true
336- } else {
337- // Anything else is either:
338- //
339- // 1. A foreign item using a non-Rust ABI (like `extern "C" { fn foo(); }`), or
340- //
341- // 2. A Rust item using a non-Rust ABI (like `extern "C" fn foo() { ... }`).
342- //
343- // Foreign items (case 1) are assumed to not unwind; it is
344- // UB otherwise. (At least for now; see also
345- // rust-lang/rust#63909 and Rust RFC 2753.)
346- //
347- // Items defined in Rust with non-Rust ABIs (case 2) are also
348- // not supposed to unwind. Whether this should be enforced
349- // (versus stating it is UB) and *how* it would be enforced
350- // is currently under discussion; see rust-lang/rust#58794.
351- //
352- // In either case, we mark item as explicitly nounwind.
353- false
354- }
355- } ,
356- ) ;
357-
358304 // Always annotate functions with the target-cpu they are compiled for.
359305 // Without this, ThinLTO won't inline Rust functions into Clang generated
360306 // functions (because Clang annotates functions this way too).
0 commit comments