@@ -126,7 +126,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
126126 args : & [ Value ] ,
127127 ) -> Cow < ' _ , [ Value ] > {
128128 if self . tcx . sess . target . is_like_windows {
129- let ( mut params, mut args) : ( Vec < _ > , Vec < _ > ) = params
129+ let ( params, args) : ( Vec < _ > , Vec < _ > ) = params
130130 . into_iter ( )
131131 . zip ( args)
132132 . map ( |( param, & arg) | {
@@ -140,29 +140,45 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
140140 } )
141141 . unzip ( ) ;
142142
143- let indirect_ret_val = returns. len ( ) == 1 && returns[ 0 ] . value_type == types:: I128 ;
143+ self . lib_call_unadjusted ( name, params, returns, & args)
144+ } else {
145+ self . lib_call_unadjusted ( name, params, returns, args)
146+ }
147+ }
144148
145- if indirect_ret_val {
146- params. insert ( 0 , AbiParam :: new ( self . pointer_type ) ) ;
147- let ret_ptr = self . create_stack_slot ( 16 , 16 ) ;
148- args. insert ( 0 , ret_ptr. get_addr ( self ) ) ;
149- self . lib_call_unadjusted ( name, params, vec ! [ ] , & args) ;
150- return Cow :: Owned ( vec ! [ ret_ptr. load( self , types:: I128 , MemFlags :: trusted( ) ) ] ) ;
149+ pub ( crate ) fn lib_call_unadjusted (
150+ & mut self ,
151+ name : & str ,
152+ mut params : Vec < AbiParam > ,
153+ returns : Vec < AbiParam > ,
154+ args : & [ Value ] ,
155+ ) -> Cow < ' _ , [ Value ] > {
156+ let adjust_ret_param =
157+ if self . tcx . sess . target . is_like_windows || self . tcx . sess . target . arch == "s390x" {
158+ returns. len ( ) == 1 && returns[ 0 ] . value_type == types:: I128
151159 } else {
152- return self . lib_call_unadjusted ( name, params, returns, & args) ;
153- }
160+ false
161+ } ;
162+
163+ if adjust_ret_param {
164+ params. insert ( 0 , AbiParam :: new ( self . pointer_type ) ) ;
165+ let ret_ptr = self . create_stack_slot ( 16 , 16 ) ;
166+ let mut args = args. to_vec ( ) ;
167+ args. insert ( 0 , ret_ptr. get_addr ( self ) ) ;
168+ self . lib_call_inner ( name, params, vec ! [ ] , & args) ;
169+ Cow :: Owned ( vec ! [ ret_ptr. load( self , types:: I128 , MemFlags :: trusted( ) ) ] )
170+ } else {
171+ Cow :: Borrowed ( self . lib_call_inner ( name, params, returns, & args) )
154172 }
155-
156- self . lib_call_unadjusted ( name, params, returns, args)
157173 }
158174
159- pub ( crate ) fn lib_call_unadjusted (
175+ fn lib_call_inner (
160176 & mut self ,
161177 name : & str ,
162178 params : Vec < AbiParam > ,
163179 returns : Vec < AbiParam > ,
164180 args : & [ Value ] ,
165- ) -> Cow < ' _ , [ Value ] > {
181+ ) -> & [ Value ] {
166182 let sig = Signature { params, returns, call_conv : self . target_config . default_call_conv } ;
167183 let func_id = self . module . declare_function ( name, Linkage :: Import , & sig) . unwrap ( ) ;
168184 let func_ref = self . module . declare_func_in_func ( func_id, & mut self . bcx . func ) ;
@@ -175,7 +191,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
175191 }
176192 let results = self . bcx . inst_results ( call_inst) ;
177193 assert ! ( results. len( ) <= 2 , "{}" , results. len( ) ) ;
178- Cow :: Borrowed ( results)
194+ results
179195 }
180196}
181197
0 commit comments