Skip to content

Commit 17365e9

Browse files
committed
Avoid depending on enable_multi_ret_implicit_sret for libcalls
1 parent 0974099 commit 17365e9

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

src/abi/mod.rs

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
144-
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())]);
143+
self.lib_call_unadjusted(name, params, returns, &args)
151144
} else {
152-
return self.lib_call_unadjusted(name, params, returns, &args);
153-
}
145+
self.lib_call_unadjusted(name, params, returns, args)
154146
}
155-
156-
self.lib_call_unadjusted(name, params, returns, args)
157147
}
158148

159149
pub(crate) fn lib_call_unadjusted(
160150
&mut self,
161151
name: &str,
162-
params: Vec<AbiParam>,
152+
mut params: Vec<AbiParam>,
163153
returns: Vec<AbiParam>,
164154
args: &[Value],
165155
) -> 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
159+
} else {
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))
172+
}
173+
}
174+
175+
fn lib_call_inner(
176+
&mut self,
177+
name: &str,
178+
params: Vec<AbiParam>,
179+
returns: Vec<AbiParam>,
180+
args: &[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

Comments
 (0)