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

This commit is contained in:
Andrew Kelley 2024-05-08 13:21:36 -07:00
parent 107d4f6683
commit e89d6fc503
3 changed files with 13 additions and 3 deletions

View File

@ -340,7 +340,7 @@ pub const Mutable = struct {
} }
const req_limbs = calcTwosCompLimbCount(bit_count); 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 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. 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; return if (self.positive) @as(T, @intCast(r)) else error.NegativeIntoUnsigned;
} else { } else {
if (self.positive) { if (self.positive) {
return @as(T, @intCast(r)); return @intCast(r);
} else { } else {
if (math.cast(T, r)) |ok| { if (math.cast(T, r)) |ok| {
return -ok; return -ok;

View File

@ -1545,7 +1545,7 @@ pub const Type = struct {
0 => .none, 0 => .none,
1...8 => .@"1", 1...8 => .@"1",
9...16 => .@"2", 9...16 => .@"2",
17...127 => .@"4", 17...64 => .@"4",
else => .@"16", else => .@"16",
}, },
.x86_64 => switch (bits) { .x86_64 => switch (bits) {

View File

@ -1077,3 +1077,13 @@ test "result location initialization of error union with OPV payload" {
_ = &c; _ = &c;
try expectEqual(0, (c catch return error.TestFailed).x); 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;
}