@@ -5,17 +5,18 @@ use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
55use rustc_codegen_ssa:: mir:: place:: { PlaceRef , PlaceValue } ;
66use rustc_codegen_ssa:: traits:: * ;
77use rustc_codegen_ssa:: MemFlags ;
8- use rustc_middle:: bug;
98use rustc_middle:: ty:: layout:: LayoutOf ;
109pub use rustc_middle:: ty:: layout:: { FAT_PTR_ADDR , FAT_PTR_EXTRA } ;
1110use rustc_middle:: ty:: Ty ;
11+ use rustc_middle:: { bug, ty} ;
1212use rustc_session:: config;
1313pub use rustc_target:: abi:: call:: * ;
1414use rustc_target:: abi:: { self , HasDataLayout , Int , Size } ;
1515pub use rustc_target:: spec:: abi:: Abi ;
1616use rustc_target:: spec:: SanitizerSet ;
1717use smallvec:: SmallVec ;
1818
19+ use crate :: attributes:: llfn_attrs_from_instance;
1920use crate :: builder:: Builder ;
2021use crate :: context:: CodegenCx ;
2122use crate :: llvm:: { self , Attribute , AttributePlace } ;
@@ -310,7 +311,16 @@ pub trait FnAbiLlvmExt<'ll, 'tcx> {
310311 fn llvm_type ( & self , cx : & CodegenCx < ' ll , ' tcx > ) -> & ' ll Type ;
311312 fn ptr_to_llvm_type ( & self , cx : & CodegenCx < ' ll , ' tcx > ) -> & ' ll Type ;
312313 fn llvm_cconv ( & self ) -> llvm:: CallConv ;
313- fn apply_attrs_llfn ( & self , cx : & CodegenCx < ' ll , ' tcx > , llfn : & ' ll Value ) ;
314+
315+ /// Apply attributes to a function declaration/definition.
316+ fn apply_attrs_llfn (
317+ & self ,
318+ cx : & CodegenCx < ' ll , ' tcx > ,
319+ llfn : & ' ll Value ,
320+ instance : Option < ty:: Instance < ' tcx > > ,
321+ ) ;
322+
323+ /// Apply attributes to a function call.
314324 fn apply_attrs_callsite ( & self , bx : & mut Builder < ' _ , ' ll , ' tcx > , callsite : & ' ll Value ) ;
315325}
316326
@@ -396,7 +406,12 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
396406 self . conv . into ( )
397407 }
398408
399- fn apply_attrs_llfn ( & self , cx : & CodegenCx < ' ll , ' tcx > , llfn : & ' ll Value ) {
409+ fn apply_attrs_llfn (
410+ & self ,
411+ cx : & CodegenCx < ' ll , ' tcx > ,
412+ llfn : & ' ll Value ,
413+ instance : Option < ty:: Instance < ' tcx > > ,
414+ ) {
400415 let mut func_attrs = SmallVec :: < [ _ ; 3 ] > :: new ( ) ;
401416 if self . ret . layout . abi . is_uninhabited ( ) {
402417 func_attrs. push ( llvm:: AttributeKind :: NoReturn . create_attr ( cx. llcx ) ) ;
@@ -477,6 +492,11 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
477492 }
478493 }
479494 }
495+
496+ // If the declaration has an associated instance, compute extra attributes based on that.
497+ if let Some ( instance) = instance {
498+ llfn_attrs_from_instance ( cx, llfn, instance) ;
499+ }
480500 }
481501
482502 fn apply_attrs_callsite ( & self , bx : & mut Builder < ' _ , ' ll , ' tcx > , callsite : & ' ll Value ) {
0 commit comments