authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-06-16 00:55:35+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-06-16 00:55:35+02:00
loga3ae499dc29747630f2801aab9bbc9661a4a0169
treeb84a1c148ffc831bab6129f5a590d097cc169ef4
parent94b69bc99fbe348a04c223eac6590e6ce5a2779c
parentdaf3cca1a491636dcd2cde45b12bc3bfcfbab69c

Merge pull request 'fix struct field alignment for big ints on s390x + fix `VaList` for hexagon and s390x' (#35780) from alexrp/zig:s390x-stuff into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35780

3 files changed, 23 insertions(+), 10 deletions(-)

lib/std/lang.zig+7-7
...@@ -1000,10 +1000,9 @@ pub const VaListArm = extern struct {...@@ -1000,10 +1000,9 @@ pub const VaListArm = extern struct {
1000/// This data structure is used by the Zig language code generation and1000/// This data structure is used by the Zig language code generation and
1001/// therefore must be kept in sync with the compiler implementation.1001/// therefore must be kept in sync with the compiler implementation.
1002pub const VaListHexagon = extern struct {1002pub const VaListHexagon = extern struct {
1003 __gpr: c_long,1003 __current_saved_reg_area_pointer: *anyopaque,
1004 __fpr: c_long,1004 __saved_reg_area_end_pointer: *anyopaque,
1005 __overflow_arg_area: *anyopaque,1005 __overflow_area_pointer: *anyopaque,
1006 __reg_save_area: *anyopaque,
1007};1006};
10081007
1009/// This data structure is used by the Zig language code generation and1008/// This data structure is used by the Zig language code generation and
...@@ -1019,9 +1018,10 @@ pub const VaListPowerPc = extern struct {...@@ -1019,9 +1018,10 @@ pub const VaListPowerPc = extern struct {
1019/// This data structure is used by the Zig language code generation and1018/// This data structure is used by the Zig language code generation and
1020/// therefore must be kept in sync with the compiler implementation.1019/// therefore must be kept in sync with the compiler implementation.
1021pub const VaListS390x = extern struct {1020pub const VaListS390x = extern struct {
1022 __current_saved_reg_area_pointer: *anyopaque,1021 __gpr: c_long,
1023 __saved_reg_area_end_pointer: *anyopaque,1022 __fpr: c_long,
1024 __overflow_area_pointer: *anyopaque,1023 __overflow_arg_area: *anyopaque,
1024 __reg_save_area: *anyopaque,
1025};1025};
10261026
1027/// This data structure is used by the Zig language code generation and1027/// This data structure is used by the Zig language code generation and
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);