From 7e1cba73fc5dce195af2c5cc6a2a1427710ed3ed Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 1 May 2024 18:17:03 -0700 Subject: [PATCH] Type.intAbiAlignment: update for LLVM 18 changes This function is intended to match what the backend desires. No kink shaming. --- src/type.zig | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/type.zig b/src/type.zig index 2afff730a7..e26cfe03f0 100644 --- a/src/type.zig +++ b/src/type.zig @@ -1540,10 +1540,30 @@ pub const Type = struct { } pub fn intAbiAlignment(bits: u16, target: Target, use_llvm: bool) Alignment { - return Alignment.fromByteUnits(@min( - std.math.ceilPowerOfTwoPromote(u16, @as(u16, @intCast((@as(u17, bits) + 7) / 8))), - maxIntAlignment(target, use_llvm), - )); + return switch (target.cpu.arch) { + .x86 => switch (bits) { + 0 => .none, + 1...8 => .@"1", + 9...16 => .@"2", + 17...127 => .@"4", + else => .@"16", + }, + .x86_64 => switch (bits) { + 0 => .none, + 1...8 => .@"1", + 9...16 => .@"2", + 17...32 => .@"4", + 33...64 => .@"8", + else => switch (target_util.zigBackend(target, use_llvm)) { + .stage2_x86_64 => .@"8", + else => .@"16", + }, + }, + else => return Alignment.fromByteUnits(@min( + std.math.ceilPowerOfTwoPromote(u16, @as(u16, @intCast((@as(u17, bits) + 7) / 8))), + maxIntAlignment(target, use_llvm), + )), + }; } pub fn maxIntAlignment(target: std.Target, use_llvm: bool) u16 {