@@ -57,7 +57,7 @@ pub(crate) unsafe fn codegen(
57
57
let from_name = mangle_internal_symbol ( tcx, & global_fn_name ( method. name ) ) ;
58
58
let to_name = mangle_internal_symbol ( tcx, & default_fn_name ( method. name ) ) ;
59
59
60
- create_wrapper_function ( tcx, & cx, & from_name, & to_name, & args, output, false ) ;
60
+ create_wrapper_function ( tcx, & cx, & from_name, Some ( & to_name) , & args, output, false ) ;
61
61
}
62
62
}
63
63
@@ -66,7 +66,7 @@ pub(crate) unsafe fn codegen(
66
66
tcx,
67
67
& cx,
68
68
& mangle_internal_symbol ( tcx, "__rust_alloc_error_handler" ) ,
69
- & mangle_internal_symbol ( tcx, alloc_error_handler_name ( alloc_error_handler_kind) ) ,
69
+ Some ( & mangle_internal_symbol ( tcx, alloc_error_handler_name ( alloc_error_handler_kind) ) ) ,
70
70
& [ usize, usize] , // size, align
71
71
None ,
72
72
true ,
@@ -81,11 +81,16 @@ pub(crate) unsafe fn codegen(
81
81
let llval = llvm:: LLVMConstInt ( i8, val as u64 , False ) ;
82
82
llvm:: set_initializer ( ll_g, llval) ;
83
83
84
- let name = mangle_internal_symbol ( tcx, NO_ALLOC_SHIM_IS_UNSTABLE ) ;
85
- let ll_g = cx. declare_global ( & name, i8) ;
86
- llvm:: set_visibility ( ll_g, llvm:: Visibility :: from_generic ( tcx. sess . default_visibility ( ) ) ) ;
87
- let llval = llvm:: LLVMConstInt ( i8, 0 , False ) ;
88
- llvm:: set_initializer ( ll_g, llval) ;
84
+ // __rust_no_alloc_shim_is_unstable
85
+ create_wrapper_function (
86
+ tcx,
87
+ & cx,
88
+ & mangle_internal_symbol ( tcx, NO_ALLOC_SHIM_IS_UNSTABLE ) ,
89
+ None ,
90
+ & [ ] ,
91
+ None ,
92
+ false ,
93
+ ) ;
89
94
}
90
95
91
96
if tcx. sess . opts . debuginfo != DebugInfo :: None {
@@ -99,7 +104,7 @@ fn create_wrapper_function(
99
104
tcx : TyCtxt < ' _ > ,
100
105
cx : & SimpleCx < ' _ > ,
101
106
from_name : & str ,
102
- to_name : & str ,
107
+ to_name : Option < & str > ,
103
108
args : & [ & Type ] ,
104
109
output : Option < & Type > ,
105
110
no_return : bool ,
@@ -128,33 +133,38 @@ fn create_wrapper_function(
128
133
attributes:: apply_to_llfn ( llfn, llvm:: AttributePlace :: Function , & [ uwtable] ) ;
129
134
}
130
135
131
- let callee = declare_simple_fn (
132
- & cx,
133
- to_name,
134
- llvm:: CallConv :: CCallConv ,
135
- llvm:: UnnamedAddr :: Global ,
136
- llvm:: Visibility :: Hidden ,
137
- ty,
138
- ) ;
139
- if let Some ( no_return) = no_return {
140
- // -> ! DIFlagNoReturn
141
- attributes:: apply_to_llfn ( callee, llvm:: AttributePlace :: Function , & [ no_return] ) ;
142
- }
143
- llvm:: set_visibility ( callee, llvm:: Visibility :: Hidden ) ;
144
-
145
136
let llbb = unsafe { llvm:: LLVMAppendBasicBlockInContext ( cx. llcx , llfn, c"entry" . as_ptr ( ) ) } ;
146
-
147
137
let mut bx = SBuilder :: build ( & cx, llbb) ;
148
- let args = args
149
- . iter ( )
150
- . enumerate ( )
151
- . map ( |( i, _) | llvm:: get_param ( llfn, i as c_uint ) )
152
- . collect :: < Vec < _ > > ( ) ;
153
- let ret = bx. call ( ty, callee, & args, None ) ;
154
- llvm:: LLVMSetTailCall ( ret, True ) ;
155
- if output. is_some ( ) {
156
- bx. ret ( ret) ;
138
+
139
+ if let Some ( to_name) = to_name {
140
+ let callee = declare_simple_fn (
141
+ & cx,
142
+ to_name,
143
+ llvm:: CallConv :: CCallConv ,
144
+ llvm:: UnnamedAddr :: Global ,
145
+ llvm:: Visibility :: Hidden ,
146
+ ty,
147
+ ) ;
148
+ if let Some ( no_return) = no_return {
149
+ // -> ! DIFlagNoReturn
150
+ attributes:: apply_to_llfn ( callee, llvm:: AttributePlace :: Function , & [ no_return] ) ;
151
+ }
152
+ llvm:: set_visibility ( callee, llvm:: Visibility :: Hidden ) ;
153
+
154
+ let args = args
155
+ . iter ( )
156
+ . enumerate ( )
157
+ . map ( |( i, _) | llvm:: get_param ( llfn, i as c_uint ) )
158
+ . collect :: < Vec < _ > > ( ) ;
159
+ let ret = bx. call ( ty, callee, & args, None ) ;
160
+ llvm:: LLVMSetTailCall ( ret, True ) ;
161
+ if output. is_some ( ) {
162
+ bx. ret ( ret) ;
163
+ } else {
164
+ bx. ret_void ( )
165
+ }
157
166
} else {
167
+ assert ! ( output. is_none( ) ) ;
158
168
bx. ret_void ( )
159
169
}
160
170
}
0 commit comments