@@ -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, context, & from_name, & to_name, & types, output) ;
60+ create_wrapper_function ( tcx, context, & from_name, Some ( & to_name) , & types, output) ;
6161 }
6262 }
6363
@@ -66,7 +66,7 @@ pub(crate) unsafe fn codegen(
6666 tcx,
6767 context,
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] ,
7171 None ,
7272 ) ;
@@ -81,21 +81,21 @@ pub(crate) unsafe fn codegen(
8181 let value = context. new_rvalue_from_int ( i8, value as i32 ) ;
8282 global. global_set_initializer_rvalue ( value) ;
8383
84- let name = mangle_internal_symbol ( tcx , NO_ALLOC_SHIM_IS_UNSTABLE ) ;
85- let global = context . new_global ( None , GlobalKind :: Exported , i8 , name ) ;
86- # [ cfg ( feature = "master" ) ]
87- global . add_attribute ( VarAttribute :: Visibility ( symbol_visibility_to_gcc (
88- tcx . sess . default_visibility ( ) ,
89- ) ) ) ;
90- let value = context . new_rvalue_from_int ( i8 , 0 ) ;
91- global . global_set_initializer_rvalue ( value ) ;
84+ create_wrapper_function (
85+ tcx ,
86+ context ,
87+ & mangle_internal_symbol ( tcx , NO_ALLOC_SHIM_IS_UNSTABLE ) ,
88+ None ,
89+ & [ ] ,
90+ None ,
91+ ) ;
9292}
9393
9494fn create_wrapper_function (
9595 tcx : TyCtxt < ' _ > ,
9696 context : & Context < ' _ > ,
9797 from_name : & str ,
98- to_name : & str ,
98+ to_name : Option < & str > ,
9999 types : & [ Type < ' _ > ] ,
100100 output : Option < Type < ' _ > > ,
101101) {
@@ -124,34 +124,40 @@ fn create_wrapper_function(
124124 // TODO(antoyo): emit unwind tables.
125125 }
126126
127- let args: Vec < _ > = types
128- . iter ( )
129- . enumerate ( )
130- . map ( |( index, typ) | context. new_parameter ( None , * typ, format ! ( "param{}" , index) ) )
131- . collect ( ) ;
132- let callee = context. new_function (
133- None ,
134- FunctionType :: Extern ,
135- output. unwrap_or ( void) ,
136- & args,
137- to_name,
138- false ,
139- ) ;
140- #[ cfg( feature = "master" ) ]
141- callee. add_attribute ( FnAttribute :: Visibility ( gccjit:: Visibility :: Hidden ) ) ;
142-
143127 let block = func. new_block ( "entry" ) ;
144128
145- let args = args
146- . iter ( )
147- . enumerate ( )
148- . map ( |( i, _) | func. get_param ( i as i32 ) . to_rvalue ( ) )
149- . collect :: < Vec < _ > > ( ) ;
150- let ret = context. new_call ( None , callee, & args) ;
151- //llvm::LLVMSetTailCall(ret, True);
152- if output. is_some ( ) {
153- block. end_with_return ( None , ret) ;
129+ if let Some ( to_name) = to_name {
130+ let args: Vec < _ > = types
131+ . iter ( )
132+ . enumerate ( )
133+ . map ( |( index, typ) | context. new_parameter ( None , * typ, format ! ( "param{}" , index) ) )
134+ . collect ( ) ;
135+ let callee = context. new_function (
136+ None ,
137+ FunctionType :: Extern ,
138+ output. unwrap_or ( void) ,
139+ & args,
140+ to_name,
141+ false ,
142+ ) ;
143+ #[ cfg( feature = "master" ) ]
144+ callee. add_attribute ( FnAttribute :: Visibility ( gccjit:: Visibility :: Hidden ) ) ;
145+
146+ let args = args
147+ . iter ( )
148+ . enumerate ( )
149+ . map ( |( i, _) | func. get_param ( i as i32 ) . to_rvalue ( ) )
150+ . collect :: < Vec < _ > > ( ) ;
151+ let ret = context. new_call ( None , callee, & args) ;
152+ //llvm::LLVMSetTailCall(ret, True);
153+ if output. is_some ( ) {
154+ block. end_with_return ( None , ret) ;
155+ } else {
156+ block. add_eval ( None , ret) ;
157+ block. end_with_void_return ( None ) ;
158+ }
154159 } else {
160+ assert ! ( output. is_none( ) ) ;
155161 block. end_with_void_return ( None ) ;
156162 }
157163
0 commit comments