@@ -57,7 +57,7 @@ pub(crate) unsafe fn codegen(
5757 let from_name = mangle_internal_symbol ( tcx, & global_fn_name ( method. name ) ) ;
5858 let to_name = mangle_internal_symbol ( tcx, & default_fn_name ( method. name ) ) ;
5959
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 ) ;
6161 }
6262 }
6363
@@ -66,7 +66,7 @@ pub(crate) unsafe fn codegen(
6666 tcx,
6767 & cx,
6868 & 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) ) ) ,
7070 & [ usize, usize] , // size, align
7171 None ,
7272 true ,
@@ -81,11 +81,16 @@ pub(crate) unsafe fn codegen(
8181 let llval = llvm:: LLVMConstInt ( i8, val as u64 , False ) ;
8282 llvm:: set_initializer ( ll_g, llval) ;
8383
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+ ) ;
8994 }
9095
9196 if tcx. sess . opts . debuginfo != DebugInfo :: None {
@@ -99,7 +104,7 @@ fn create_wrapper_function(
99104 tcx : TyCtxt < ' _ > ,
100105 cx : & SimpleCx < ' _ > ,
101106 from_name : & str ,
102- to_name : & str ,
107+ to_name : Option < & str > ,
103108 args : & [ & Type ] ,
104109 output : Option < & Type > ,
105110 no_return : bool ,
@@ -128,33 +133,38 @@ fn create_wrapper_function(
128133 attributes:: apply_to_llfn ( llfn, llvm:: AttributePlace :: Function , & [ uwtable] ) ;
129134 }
130135
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-
145136 let llbb = unsafe { llvm:: LLVMAppendBasicBlockInContext ( cx. llcx , llfn, c"entry" . as_ptr ( ) ) } ;
146-
147137 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+ }
157166 } else {
167+ assert ! ( output. is_none( ) ) ;
158168 bx. ret_void ( )
159169 }
160170}
0 commit comments