From e89d6fc5037f4271396cb6acf3488f158aaacbae Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 8 May 2024 13:21:36 -0700 Subject: [PATCH] fix wrong int alignment for i65..i127 on x86 arch --- lib/std/math/big/int.zig | 4 ++-- src/type.zig | 2 +- test/behavior/error.zig | 10 ++++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/std/math/big/int.zig b/lib/std/math/big/int.zig index 93ad1ccbe2..0a5c3c6ca5 100644 --- a/lib/std/math/big/int.zig +++ b/lib/std/math/big/int.zig @@ -340,7 +340,7 @@ pub const Mutable = struct { } const req_limbs = calcTwosCompLimbCount(bit_count); - const bit = @as(Log2Limb, @truncate(bit_count - 1)); + const bit: Log2Limb = @truncate(bit_count - 1); const signmask = @as(Limb, 1) << bit; // 0b0..010..0 where 1 is the sign bit. const mask = (signmask << 1) -% 1; // 0b0..011..1 where the leftmost 1 is the sign bit. @@ -2186,7 +2186,7 @@ pub const Const = struct { return if (self.positive) @as(T, @intCast(r)) else error.NegativeIntoUnsigned; } else { if (self.positive) { - return @as(T, @intCast(r)); + return @intCast(r); } else { if (math.cast(T, r)) |ok| { return -ok; diff --git a/src/type.zig b/src/type.zig index e26cfe03f0..5dad904ca0 100644 --- a/src/type.zig +++ b/src/type.zig @@ -1545,7 +1545,7 @@ pub const Type = struct { 0 => .none, 1...8 => .@"1", 9...16 => .@"2", - 17...127 => .@"4", + 17...64 => .@"4", else => .@"16", }, .x86_64 => switch (bits) { diff --git a/test/behavior/error.zig b/test/behavior/error.zig index 408dc96005..7703a02f68 100644 --- a/test/behavior/error.zig +++ b/test/behavior/error.zig @@ -1077,3 +1077,13 @@ test "result location initialization of error union with OPV payload" { _ = &c; try expectEqual(0, (c catch return error.TestFailed).x); } + +test "return error union with i65" { + if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; + + try expect(try add(1000, 234) == 1234); +} + +fn add(x: i65, y: i65) anyerror!i65 { + return x + y; +}