@@ -5,9 +5,10 @@ use rustc_ast::expand::allocator::{
55} ;
66use rustc_codegen_ssa:: traits:: BaseTypeCodegenMethods as _;
77use rustc_middle:: bug;
8- use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrs ;
8+ use rustc_middle:: middle:: codegen_fn_attrs:: { CodegenFnAttrFlags , CodegenFnAttrs } ;
99use rustc_middle:: ty:: TyCtxt ;
1010use rustc_session:: config:: { DebugInfo , OomStrategy } ;
11+ use rustc_span:: sym;
1112use rustc_symbol_mangling:: mangle_internal_symbol;
1213
1314use crate :: attributes:: llfn_attrs_from_instance;
@@ -59,7 +60,26 @@ pub(crate) unsafe fn codegen(
5960 let from_name = mangle_internal_symbol ( tcx, & global_fn_name ( method. name ) ) ;
6061 let to_name = mangle_internal_symbol ( tcx, & default_fn_name ( method. name ) ) ;
6162
62- create_wrapper_function ( tcx, & cx, & from_name, Some ( & to_name) , & args, output, false ) ;
63+ let alloc_attr_flag = match method. name {
64+ sym:: alloc => CodegenFnAttrFlags :: ALLOCATOR ,
65+ sym:: dealloc => CodegenFnAttrFlags :: DEALLOCATOR ,
66+ sym:: realloc => CodegenFnAttrFlags :: REALLOCATOR ,
67+ sym:: alloc_zeroed => CodegenFnAttrFlags :: ALLOCATOR_ZEROED ,
68+ _ => unreachable ! ( "Unknown allocator method!" ) ,
69+ } ;
70+
71+ let mut attrs = CodegenFnAttrs :: new ( ) ;
72+ attrs. flags |= alloc_attr_flag;
73+ create_wrapper_function (
74+ tcx,
75+ & cx,
76+ & from_name,
77+ Some ( & to_name) ,
78+ & args,
79+ output,
80+ false ,
81+ & attrs,
82+ ) ;
6383 }
6484 }
6585
@@ -72,6 +92,7 @@ pub(crate) unsafe fn codegen(
7292 & [ usize, usize] , // size, align
7393 None ,
7494 true ,
95+ & CodegenFnAttrs :: new ( ) ,
7596 ) ;
7697
7798 unsafe {
@@ -93,6 +114,7 @@ pub(crate) unsafe fn codegen(
93114 & [ ] ,
94115 None ,
95116 false ,
117+ & CodegenFnAttrs :: new ( ) ,
96118 ) ;
97119 }
98120
@@ -139,6 +161,7 @@ fn create_wrapper_function(
139161 args : & [ & Type ] ,
140162 output : Option < & Type > ,
141163 no_return : bool ,
164+ attrs : & CodegenFnAttrs ,
142165) {
143166 let ty = cx. type_func ( args, output. unwrap_or_else ( || cx. type_void ( ) ) ) ;
144167 let llfn = declare_simple_fn (
@@ -150,8 +173,7 @@ fn create_wrapper_function(
150173 ty,
151174 ) ;
152175
153- let attrs = CodegenFnAttrs :: new ( ) ;
154- llfn_attrs_from_instance ( cx, tcx, llfn, & attrs, None ) ;
176+ llfn_attrs_from_instance ( cx, tcx, llfn, attrs, None ) ;
155177
156178 let no_return = if no_return {
157179 // -> ! DIFlagNoReturn
0 commit comments