zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 200e06b2399d605c8d183e55649e39ba2c6b56f6 (tree)
parent 927f24a6ff4af55f79df54c392b906413eae1459
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Tue, 30 Apr 2024 19:51:35 -0700

update maxIntAlignment for x86 to 16

LLVMABIAlignmentOfType(i128) reports 16 on this target, however the C
ABI uses align(4).

Clang in LLVM 17 does this:

%struct.foo = type { i32, i128 }

Clang in LLVM 18 does this:

%struct.foo = type <{ i32, i128 }>

Clang is working around the 16-byte alignment to use align(4) for the C
ABI by making the LLVM struct packed.

Diffstat:
Msrc/type.zig | 6+-----
Mtest/behavior/align.zig | 39+--------------------------------------
2 files changed, 2 insertions(+), 43 deletions(-)

diff --git a/src/type.zig b/src/type.zig @@ -1572,11 +1572,6 @@ pub const Type = struct { .wasm64, => 8, - .x86 => if (target.ofmt == .c) 16 else return switch (target.os.tag) { - .windows, .uefi => 8, - else => 4, - }, - // For these, LLVMABIAlignmentOfType(i128) reports 8. Note that 16 // is a relevant number in three cases: // 1. Different machine code instruction when loading into SIMD register. @@ -1599,6 +1594,7 @@ pub const Type = struct { }, // Even LLVMABIAlignmentOfType(i128) agrees on these targets. + .x86, .aarch64, .aarch64_be, .aarch64_32, diff --git a/test/behavior/align.zig b/test/behavior/align.zig @@ -114,44 +114,6 @@ test "alignment and size of structs with 128-bit fields" { .u129_size = 24, }, - .x86 => if (builtin.object_format == .c) .{ - .a_align = 16, - .a_size = 16, - - .b_align = 16, - .b_size = 32, - - .u128_align = 16, - .u128_size = 16, - .u129_align = 16, - .u129_size = 32, - } else switch (builtin.os.tag) { - .windows => .{ - .a_align = 8, - .a_size = 16, - - .b_align = 16, - .b_size = 32, - - .u128_align = 8, - .u128_size = 16, - .u129_align = 8, - .u129_size = 24, - }, - else => .{ - .a_align = 4, - .a_size = 16, - - .b_align = 16, - .b_size = 32, - - .u128_align = 4, - .u128_size = 16, - .u129_align = 4, - .u129_size = 20, - }, - }, - .mips64, .mips64el, .powerpc64, @@ -211,6 +173,7 @@ test "alignment and size of structs with 128-bit fields" { }, }, + .x86, .aarch64, .aarch64_be, .aarch64_32,