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) {
26722672 const big_int = int.storage.toBigInt(&buffer);
26732673
26742674 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());
26762676 for (big_int.limbs) |limb| std.hash.autoHash(&hasher, limb);
26772677 return hasher.final();
26782678 },
......@@ -7682,7 +7682,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerThread.Id, key:
76827682 return gop.put();
76837683 } 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;
76867686 try addInt(ip, gpa, io, tid, int.ty, tag, big_int.limbs);
76877687 },
76887688 inline .u64, .i64 => |x| {
......@@ -7699,7 +7699,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerThread.Id, key:
76997699
77007700 var buf: [2]Limb = undefined;
77017701 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;
77037703 try addInt(ip, gpa, io, tid, int.ty, tag, big_int.limbs);
77047704 },
77057705 }
test/behavior/math.zig+7
......@@ -2691,3 +2691,10 @@ test "i96 operations" {
26912691 try expect(12345678910111213 == Op_i96.do(.{ .b = .{ .inner = .{ .x = 1234567891011121314 }, .flag = true } }));
26922692 try expect(1234567891021121314 == Op_i96.do(.{ .c = .{ .inner = .{ .x = 123456789101112131415 }, .flag = true } }));
26932693}
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}