Commit 200e06b239

Andrew Kelley <andrew@ziglang.org>
2024-05-01 04:51:35
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.
1 parent 927f24a
Changed files (2)
src
test
behavior
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,
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,