@@ -5,9 +5,10 @@ use rustc_ast::expand::allocator::{
5
5
} ;
6
6
use rustc_codegen_ssa:: traits:: BaseTypeCodegenMethods as _;
7
7
use rustc_middle:: bug;
8
- use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrs ;
8
+ use rustc_middle:: middle:: codegen_fn_attrs:: { CodegenFnAttrFlags , CodegenFnAttrs } ;
9
9
use rustc_middle:: ty:: TyCtxt ;
10
10
use rustc_session:: config:: { DebugInfo , OomStrategy } ;
11
+ use rustc_span:: sym;
11
12
use rustc_symbol_mangling:: mangle_internal_symbol;
12
13
13
14
use crate :: attributes:: llfn_attrs_from_instance;
@@ -59,7 +60,26 @@ pub(crate) unsafe fn codegen(
59
60
let from_name = mangle_internal_symbol ( tcx, & global_fn_name ( method. name ) ) ;
60
61
let to_name = mangle_internal_symbol ( tcx, & default_fn_name ( method. name ) ) ;
61
62
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
+ ) ;
63
83
}
64
84
}
65
85
@@ -72,6 +92,7 @@ pub(crate) unsafe fn codegen(
72
92
& [ usize, usize] , // size, align
73
93
None ,
74
94
true ,
95
+ & CodegenFnAttrs :: new ( ) ,
75
96
) ;
76
97
77
98
unsafe {
@@ -93,6 +114,7 @@ pub(crate) unsafe fn codegen(
93
114
& [ ] ,
94
115
None ,
95
116
false ,
117
+ & CodegenFnAttrs :: new ( ) ,
96
118
) ;
97
119
}
98
120
@@ -139,6 +161,7 @@ fn create_wrapper_function(
139
161
args : & [ & Type ] ,
140
162
output : Option < & Type > ,
141
163
no_return : bool ,
164
+ attrs : & CodegenFnAttrs ,
142
165
) {
143
166
let ty = cx. type_func ( args, output. unwrap_or_else ( || cx. type_void ( ) ) ) ;
144
167
let llfn = declare_simple_fn (
@@ -150,8 +173,7 @@ fn create_wrapper_function(
150
173
ty,
151
174
) ;
152
175
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 ) ;
155
177
156
178
let no_return = if no_return {
157
179
// -> ! DIFlagNoReturn
0 commit comments