Fix C aggregate-passing ABI on powerpc
The existing code (which looks like it was copied from MIPS) passes aggregates by value in registers. This is wrong. According to the SVR4 powerpc psABI, all aggregates are passed indirectly. See #64259 for more discussion, which addresses the ABI for the special case of ZSTs (empty structs).
This commit is contained in:
parent
1423bec54c
commit
e648aa8e89
2 changed files with 11 additions and 32 deletions
|
@ -554,7 +554,7 @@ impl<'a, Ty> FnAbi<'a, Ty> {
|
||||||
"arm" => arm::compute_abi_info(cx, self),
|
"arm" => arm::compute_abi_info(cx, self),
|
||||||
"mips" => mips::compute_abi_info(cx, self),
|
"mips" => mips::compute_abi_info(cx, self),
|
||||||
"mips64" => mips64::compute_abi_info(cx, self),
|
"mips64" => mips64::compute_abi_info(cx, self),
|
||||||
"powerpc" => powerpc::compute_abi_info(cx, self),
|
"powerpc" => powerpc::compute_abi_info(self),
|
||||||
"powerpc64" => powerpc64::compute_abi_info(cx, self),
|
"powerpc64" => powerpc64::compute_abi_info(cx, self),
|
||||||
"s390x" => s390x::compute_abi_info(cx, self),
|
"s390x" => s390x::compute_abi_info(cx, self),
|
||||||
"msp430" => msp430::compute_abi_info(self),
|
"msp430" => msp430::compute_abi_info(self),
|
||||||
|
|
|
@ -1,49 +1,28 @@
|
||||||
use crate::abi::call::{ArgAbi, FnAbi, Reg, Uniform};
|
use crate::abi::call::{ArgAbi, FnAbi};
|
||||||
use crate::abi::{HasDataLayout, LayoutOf, Size, TyLayoutMethods};
|
|
||||||
|
|
||||||
fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'_, Ty>, offset: &mut Size)
|
fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) {
|
||||||
where Ty: TyLayoutMethods<'a, C>, C: LayoutOf<Ty = Ty> + HasDataLayout
|
if ret.layout.is_aggregate() {
|
||||||
{
|
|
||||||
if !ret.layout.is_aggregate() {
|
|
||||||
ret.extend_integer_width_to(32);
|
|
||||||
} else {
|
|
||||||
ret.make_indirect();
|
ret.make_indirect();
|
||||||
*offset += cx.data_layout().pointer_size;
|
} else {
|
||||||
|
ret.extend_integer_width_to(32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'_, Ty>, offset: &mut Size)
|
fn classify_arg<Ty>(arg: &mut ArgAbi<'_, Ty>) {
|
||||||
where Ty: TyLayoutMethods<'a, C>, C: LayoutOf<Ty = Ty> + HasDataLayout
|
|
||||||
{
|
|
||||||
let dl = cx.data_layout();
|
|
||||||
let size = arg.layout.size;
|
|
||||||
let align = arg.layout.align.max(dl.i32_align).min(dl.i64_align).abi;
|
|
||||||
|
|
||||||
if arg.layout.is_aggregate() {
|
if arg.layout.is_aggregate() {
|
||||||
arg.cast_to(Uniform {
|
arg.make_indirect();
|
||||||
unit: Reg::i32(),
|
|
||||||
total: size
|
|
||||||
});
|
|
||||||
if !offset.is_aligned(align) {
|
|
||||||
arg.pad_with(Reg::i32());
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
arg.extend_integer_width_to(32);
|
arg.extend_integer_width_to(32);
|
||||||
}
|
}
|
||||||
|
|
||||||
*offset = offset.align_to(align) + size.align_to(align);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'_, Ty>)
|
pub fn compute_abi_info<Ty>(fn_abi: &mut FnAbi<'_, Ty>) {
|
||||||
where Ty: TyLayoutMethods<'a, C>, C: LayoutOf<Ty = Ty> + HasDataLayout
|
|
||||||
{
|
|
||||||
let mut offset = Size::ZERO;
|
|
||||||
if !fn_abi.ret.is_ignore() {
|
if !fn_abi.ret.is_ignore() {
|
||||||
classify_ret(cx, &mut fn_abi.ret, &mut offset);
|
classify_ret(&mut fn_abi.ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
for arg in &mut fn_abi.args {
|
for arg in &mut fn_abi.args {
|
||||||
if arg.is_ignore() { continue; }
|
if arg.is_ignore() { continue; }
|
||||||
classify_arg(cx, arg, &mut offset);
|
classify_arg(arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue