@@ -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, context, & from_name, & to_name, & types, output) ;
60
+ create_wrapper_function ( tcx, context, & from_name, Some ( & to_name) , & types, output) ;
61
61
}
62
62
}
63
63
@@ -66,7 +66,7 @@ pub(crate) unsafe fn codegen(
66
66
tcx,
67
67
context,
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] ,
71
71
None ,
72
72
) ;
@@ -81,21 +81,21 @@ pub(crate) unsafe fn codegen(
81
81
let value = context. new_rvalue_from_int ( i8, value as i32 ) ;
82
82
global. global_set_initializer_rvalue ( value) ;
83
83
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
+ ) ;
92
92
}
93
93
94
94
fn create_wrapper_function (
95
95
tcx : TyCtxt < ' _ > ,
96
96
context : & Context < ' _ > ,
97
97
from_name : & str ,
98
- to_name : & str ,
98
+ to_name : Option < & str > ,
99
99
types : & [ Type < ' _ > ] ,
100
100
output : Option < Type < ' _ > > ,
101
101
) {
@@ -124,34 +124,40 @@ fn create_wrapper_function(
124
124
// TODO(antoyo): emit unwind tables.
125
125
}
126
126
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
-
143
127
let block = func. new_block ( "entry" ) ;
144
128
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
+ }
154
159
} else {
160
+ assert ! ( output. is_none( ) ) ;
155
161
block. end_with_void_return ( None ) ;
156
162
}
157
163
0 commit comments