Commit e89d6fc503

Andrew Kelley <andrew@ziglang.org>
2024-05-08 22:21:36
fix wrong int alignment for i65..i127 on x86 arch
1 parent 107d4f6
Changed files (3)
lib
std
math
src
test
behavior
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;
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) {
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;
+}