authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-06-15 14:17:03+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-06-15 14:36:41+02:00
logdaf3cca1a491636dcd2cde45b12bc3bfcfbab69c
treece70b0b65542e31f9a418411377bebdfab1f4bf1
parent47e208e554776aa4f5f3fe74d6f8d995efa3aaad
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

compiler: fix struct field alignment for big ints on s390x

contributes to https://codeberg.org/ziglang/zig/issues/35523

2 files changed, 16 insertions(+), 3 deletions(-)

src/Type.zig+1-1
...@@ -2521,7 +2521,7 @@ pub fn defaultStructFieldAlignment(...@@ -2521,7 +2521,7 @@ pub fn defaultStructFieldAlignment(
2521 ((field_ty.isAbiInt(zcu) and field_ty.intInfo(zcu).bits > 64) or2521 ((field_ty.isAbiInt(zcu) and field_ty.intInfo(zcu).bits > 64) or
2522 (field_ty.toIntern() == .f80_type and zcu.getTarget().cTypeBitSize(.longdouble) != 80)))2522 (field_ty.toIntern() == .f80_type and zcu.getTarget().cTypeBitSize(.longdouble) != 80)))
2523 {2523 {
2524 return abi_align.maxStrict(.@"16");2524 return abi_align.maxStrict(if (zcu.getTarget().cpu.arch == .s390x) .@"8" else .@"16");
2525 }2525 }
2526 return abi_align;2526 return abi_align;
2527}2527}
test/behavior/align.zig+15-2
...@@ -133,6 +133,20 @@ test "alignment and size of structs with 128-bit fields" {...@@ -133,6 +133,20 @@ test "alignment and size of structs with 128-bit fields" {
133 y: u8,133 y: u8,
134 };134 };
135 const expected = switch (builtin.cpu.arch) {135 const expected = switch (builtin.cpu.arch) {
136 .s390x,
137 => .{
138 .a_align = 8,
139 .a_size = 16,
140
141 .b_align = 8,
142 .b_size = 24,
143
144 .u128_align = 8,
145 .u128_size = 16,
146 .u129_align = 8,
147 .u129_size = 24,
148 },
149
136 .amdgcn,150 .amdgcn,
137 .arm,151 .arm,
138 .armeb,152 .armeb,
...@@ -145,7 +159,6 @@ test "alignment and size of structs with 128-bit fields" {...@@ -145,7 +159,6 @@ test "alignment and size of structs with 128-bit fields" {
145 .powerpc,159 .powerpc,
146 .powerpcle,160 .powerpcle,
147 .riscv32,161 .riscv32,
148 .s390x,
149 => .{162 => .{
150 .a_align = 8,163 .a_align = 8,
151 .a_size = 16,164 .a_size = 16,
...@@ -191,7 +204,7 @@ test "alignment and size of structs with 128-bit fields" {...@@ -191,7 +204,7 @@ test "alignment and size of structs with 128-bit fields" {
191204
192 else => return error.SkipZigTest,205 else => return error.SkipZigTest,
193 };206 };
194 const min_struct_align = if (builtin.zig_backend == .stage2_c) 16 else 0;207 const min_struct_align = if (builtin.zig_backend == .stage2_c) if (builtin.cpu.arch == .s390x) 8 else 16 else 0;
195 comptime {208 comptime {
196 assert(@alignOf(A) == @max(expected.a_align, min_struct_align));209 assert(@alignOf(A) == @max(expected.a_align, min_struct_align));
197 assert(@sizeOf(A) == expected.a_size);210 assert(@sizeOf(A) == expected.a_size);