authorgravatar for rpkak@noreply.codeberg.orgrpkak <rpkak@noreply.codeberg.org> 2026-08-11 10:22:28+02:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-08-11 10:22:28+02:00
logde207594e40d659eb2d6d9fd3813c66ee5ae4340
treef80df93f5206ac1f0bd06a367a7a16ad28021142
parentb38d176bba090beb0fc17eeaef26d52ddab04239

InternPool: don't differentiate between positive and negative zero for ints (#36451)

Added a test, which fails on master. Reviewed-on: https://codeberg.org/ziglang/zig/pulls/36451 Reviewed-by: mlugg <mlugg@mlugg.co.uk>

2 files changed, 10 insertions(+), 3 deletions(-)

src/InternPool.zig+3-3
...@@ -2672,7 +2672,7 @@ pub const Key = union(enum) {...@@ -2672,7 +2672,7 @@ pub const Key = union(enum) {
2672 const big_int = int.storage.toBigInt(&buffer);2672 const big_int = int.storage.toBigInt(&buffer);
26732673
2674 std.hash.autoHash(&hasher, int.ty);2674 std.hash.autoHash(&hasher, int.ty);
2675 std.hash.autoHash(&hasher, big_int.positive);2675 std.hash.autoHash(&hasher, big_int.positive or big_int.eqlZero());
2676 for (big_int.limbs) |limb| std.hash.autoHash(&hasher, limb);2676 for (big_int.limbs) |limb| std.hash.autoHash(&hasher, limb);
2677 return hasher.final();2677 return hasher.final();
2678 },2678 },
...@@ -7682,7 +7682,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerThread.Id, key:...@@ -7682,7 +7682,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerThread.Id, key:
7682 return gop.put();7682 return gop.put();
7683 } else |_| {}7683 } else |_| {}
76847684
7685 const tag: Tag = if (big_int.positive) .int_positive else .int_negative;7685 const tag: Tag = if (big_int.positive or big_int.eqlZero()) .int_positive else .int_negative;
7686 try addInt(ip, gpa, io, tid, int.ty, tag, big_int.limbs);7686 try addInt(ip, gpa, io, tid, int.ty, tag, big_int.limbs);
7687 },7687 },
7688 inline .u64, .i64 => |x| {7688 inline .u64, .i64 => |x| {
...@@ -7699,7 +7699,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerThread.Id, key:...@@ -7699,7 +7699,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerThread.Id, key:
76997699
7700 var buf: [2]Limb = undefined;7700 var buf: [2]Limb = undefined;
7701 const big_int = BigIntMutable.init(&buf, x).toConst();7701 const big_int = BigIntMutable.init(&buf, x).toConst();
7702 const tag: Tag = if (big_int.positive) .int_positive else .int_negative;7702 const tag: Tag = if (big_int.positive or big_int.eqlZero()) .int_positive else .int_negative;
7703 try addInt(ip, gpa, io, tid, int.ty, tag, big_int.limbs);7703 try addInt(ip, gpa, io, tid, int.ty, tag, big_int.limbs);
7704 },7704 },
7705 }7705 }
test/behavior/math.zig+7
...@@ -2691,3 +2691,10 @@ test "i96 operations" {...@@ -2691,3 +2691,10 @@ test "i96 operations" {
2691 try expect(12345678910111213 == Op_i96.do(.{ .b = .{ .inner = .{ .x = 1234567891011121314 }, .flag = true } }));2691 try expect(12345678910111213 == Op_i96.do(.{ .b = .{ .inner = .{ .x = 1234567891011121314 }, .flag = true } }));
2692 try expect(1234567891021121314 == Op_i96.do(.{ .c = .{ .inner = .{ .x = 123456789101112131415 }, .flag = true } }));2692 try expect(1234567891021121314 == Op_i96.do(.{ .c = .{ .inner = .{ .x = 123456789101112131415 }, .flag = true } }));
2693}2693}
2694
2695test "zero returned from @mod matches zero in switch" {
2696 try expect(switch (@mod(-2, 2)) {
2697 0 => true,
2698 else => false,
2699 });
2700}