commit daf3cca1a491636dcd2cde45b12bc3bfcfbab69c (tree)
parent 47e208e554776aa4f5f3fe74d6f8d995efa3aaad
Author: Alex Rønne Petersen <alex@alexrp.com>
Date: Mon, 15 Jun 2026 14:17:03 +0200
compiler: fix struct field alignment for big ints on s390x
contributes to https://codeberg.org/ziglang/zig/issues/35523
Diffstat:
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/src/Type.zig b/src/Type.zig
@@ -2521,7 +2521,7 @@ pub fn defaultStructFieldAlignment(
((field_ty.isAbiInt(zcu) and field_ty.intInfo(zcu).bits > 64) or
(field_ty.toIntern() == .f80_type and zcu.getTarget().cTypeBitSize(.longdouble) != 80)))
{
- return abi_align.maxStrict(.@"16");
+ return abi_align.maxStrict(if (zcu.getTarget().cpu.arch == .s390x) .@"8" else .@"16");
}
return abi_align;
}
diff --git a/test/behavior/align.zig b/test/behavior/align.zig
@@ -133,6 +133,20 @@ test "alignment and size of structs with 128-bit fields" {
y: u8,
};
const expected = switch (builtin.cpu.arch) {
+ .s390x,
+ => .{
+ .a_align = 8,
+ .a_size = 16,
+
+ .b_align = 8,
+ .b_size = 24,
+
+ .u128_align = 8,
+ .u128_size = 16,
+ .u129_align = 8,
+ .u129_size = 24,
+ },
+
.amdgcn,
.arm,
.armeb,
@@ -145,7 +159,6 @@ test "alignment and size of structs with 128-bit fields" {
.powerpc,
.powerpcle,
.riscv32,
- .s390x,
=> .{
.a_align = 8,
.a_size = 16,
@@ -191,7 +204,7 @@ test "alignment and size of structs with 128-bit fields" {
else => return error.SkipZigTest,
};
- const min_struct_align = if (builtin.zig_backend == .stage2_c) 16 else 0;
+ const min_struct_align = if (builtin.zig_backend == .stage2_c) if (builtin.cpu.arch == .s390x) 8 else 16 else 0;
comptime {
assert(@alignOf(A) == @max(expected.a_align, min_struct_align));
assert(@sizeOf(A) == expected.a_size);