@@ -33,6 +33,7 @@ use rustc_span::def_id::DefId;
3333use rustc_target:: callconv:: FnAbi ;
3434use rustc_target:: spec:: { HasTargetSpec , HasX86AbiOpt , Target , X86Abi } ;
3535
36+ use crate :: abi:: FnAbiGccExt ;
3637use crate :: common:: { SignType , TypeReflection , type_is_pointer} ;
3738use crate :: context:: CodegenCx ;
3839use crate :: errors;
@@ -213,6 +214,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
213214 _typ : & str ,
214215 func_ptr : RValue < ' gcc > ,
215216 args : & ' b [ RValue < ' gcc > ] ,
217+ on_stack_param_indices : & FxHashSet < usize > ,
216218 ) -> Cow < ' b , [ RValue < ' gcc > ] > {
217219 let mut all_args_match = true ;
218220 let mut param_types = vec ! [ ] ;
@@ -225,11 +227,6 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
225227 param_types. push ( param) ;
226228 }
227229
228- let mut on_stack_param_indices = FxHashSet :: default ( ) ;
229- if let Some ( indices) = self . on_stack_params . borrow ( ) . get ( & gcc_func) {
230- on_stack_param_indices. clone_from ( indices) ;
231- }
232-
233230 if all_args_match {
234231 return Cow :: Borrowed ( args) ;
235232 }
@@ -351,19 +348,24 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
351348 fn function_ptr_call (
352349 & mut self ,
353350 typ : Type < ' gcc > ,
351+ fn_abi : Option < & FnAbi < ' tcx , Ty < ' tcx > > > ,
354352 mut func_ptr : RValue < ' gcc > ,
355353 args : & [ RValue < ' gcc > ] ,
356354 _funclet : Option < & Funclet > ,
357355 ) -> RValue < ' gcc > {
358- let gcc_func = match func_ptr. get_type ( ) . dyncast_function_ptr_type ( ) {
359- Some ( func) => func,
360- None => {
361- // NOTE: due to opaque pointers now being used, we need to cast here.
362- let new_func_type = typ. dyncast_function_ptr_type ( ) . expect ( "function ptr" ) ;
356+ let func_ptr_type = {
357+ let func_ptr_type = func_ptr. get_type ( ) ;
358+ if func_ptr_type != typ {
363359 func_ptr = self . context . new_cast ( self . location , func_ptr, typ) ;
364- new_func_type
360+ typ
361+ } else {
362+ func_ptr_type
365363 }
366364 } ;
365+ let gcc_func = func_ptr_type. dyncast_function_ptr_type ( ) . expect ( "function ptr" ) ;
366+ let on_stack_param_indices = fn_abi
367+ . map ( |fn_abi| fn_abi. gcc_type ( self . cx ) . on_stack_param_indices )
368+ . unwrap_or_default ( ) ;
367369 let func_name = format ! ( "{:?}" , func_ptr) ;
368370 let previous_arg_count = args. len ( ) ;
369371 let orig_args = args;
@@ -372,7 +374,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
372374 llvm:: adjust_intrinsic_arguments ( self , gcc_func, args. into ( ) , & func_name)
373375 } ;
374376 let args_adjusted = args. len ( ) != previous_arg_count;
375- let args = self . check_ptr_call ( "call" , func_ptr, & args) ;
377+ let args = self . check_ptr_call ( "call" , func_ptr, & args, & on_stack_param_indices ) ;
376378
377379 // gccjit requires to use the result of functions, even when it's not used.
378380 // That's why we assign the result to a local or call add_eval().
@@ -599,7 +601,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
599601 & mut self ,
600602 typ : Type < ' gcc > ,
601603 fn_attrs : Option < & CodegenFnAttrs > ,
602- _fn_abi : Option < & FnAbi < ' tcx , Ty < ' tcx > > > ,
604+ fn_abi : Option < & FnAbi < ' tcx , Ty < ' tcx > > > ,
603605 func : RValue < ' gcc > ,
604606 args : & [ RValue < ' gcc > ] ,
605607 then : Block < ' gcc > ,
@@ -611,7 +613,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
611613
612614 let current_block = self . block ;
613615 self . block = try_block;
614- let call = self . call ( typ, fn_attrs, None , func, args, None , instance) ; // FIXME(antoyo): use funclet here?
616+ let call = self . call ( typ, fn_attrs, fn_abi , func, args, None , instance) ; // FIXME(antoyo): use funclet here?
615617 self . block = current_block;
616618
617619 let return_value =
@@ -645,7 +647,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
645647 _funclet : Option < & Funclet > ,
646648 instance : Option < Instance < ' tcx > > ,
647649 ) -> RValue < ' gcc > {
648- let call_site = self . call ( typ, fn_attrs, None , func, args, None , instance) ;
650+ let call_site = self . call ( typ, fn_attrs, fn_abi , func, args, None , instance) ;
649651 let condition = self . context . new_rvalue_from_int ( self . bool_type , 1 ) ;
650652 self . llbb ( ) . end_with_conditional ( self . location , condition, then, catch) ;
651653 if let Some ( _fn_abi) = fn_abi {
@@ -1773,7 +1775,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
17731775 self . function_call ( func, args, funclet)
17741776 } else {
17751777 // If it's a not function that was defined, it's a function pointer.
1776- self . function_ptr_call ( typ, func, args, funclet)
1778+ self . function_ptr_call ( typ, fn_abi , func, args, funclet)
17771779 } ;
17781780 if let Some ( _fn_abi) = fn_abi {
17791781 // FIXME(bjorn3): Apply function attributes
0 commit comments