zig

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

commit e89d6fc5037f4271396cb6acf3488f158aaacbae (tree)
parent 107d4f668342cce492150ef8763f56008058f0bc
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Wed,  8 May 2024 13:21:36 -0700

fix wrong int alignment for i65..i127 on x86 arch

Diffstat:
Mlib/std/math/big/int.zig | 4++--
Msrc/type.zig | 2+-
Mtest/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 @@ -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 @@ -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 @@ -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; +}