authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-05-29 21:47:34-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:47:57-07:00
loga803e9cf48e9566638e6ec1e23fe0b885e2651ee
tree931d88834f2a1292dffb4a44207b2295d626212b
parent66ae42bb72a9ad4b1cd44b32fa5be322b07a5ffb

Sema: fix vector comparison and interning of -0


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

lib/std/math/big/int.zig+3
...@@ -2158,6 +2158,9 @@ pub const Const = struct {...@@ -2158,6 +2158,9 @@ pub const Const = struct {
2158 pub fn to(self: Const, comptime T: type) ConvertError!T {2158 pub fn to(self: Const, comptime T: type) ConvertError!T {
2159 switch (@typeInfo(T)) {2159 switch (@typeInfo(T)) {
2160 .Int => |info| {2160 .Int => |info| {
2161 // Make sure -0 is handled correctly.
2162 if (self.eqZero()) return 0;
2163
2161 const UT = std.meta.Int(.unsigned, info.bits);2164 const UT = std.meta.Int(.unsigned, info.bits);
21622165
2163 if (!self.fitsInTwosComp(info.signedness, info.bits)) {2166 if (!self.fitsInTwosComp(info.signedness, info.bits)) {
src/Sema.zig+6-3
...@@ -34538,10 +34538,13 @@ fn compareScalar(...@@ -34538,10 +34538,13 @@ fn compareScalar(
34538 rhs: Value,34538 rhs: Value,
34539 ty: Type,34539 ty: Type,
34540) CompileError!bool {34540) CompileError!bool {
34541 const mod = sema.mod;
34542 const coerced_lhs = try mod.getCoerced(lhs, ty);
34543 const coerced_rhs = try mod.getCoerced(rhs, ty);
34541 switch (op) {34544 switch (op) {
34542 .eq => return sema.valuesEqual(lhs, rhs, ty),34545 .eq => return sema.valuesEqual(coerced_lhs, coerced_rhs, ty),
34543 .neq => return !(try sema.valuesEqual(lhs, rhs, ty)),34546 .neq => return !(try sema.valuesEqual(coerced_lhs, coerced_rhs, ty)),
34544 else => return Value.compareHeteroAdvanced(lhs, op, rhs, sema.mod, sema),34547 else => return Value.compareHeteroAdvanced(coerced_lhs, op, coerced_rhs, mod, sema),
34545 }34548 }
34546}34549}
3454734550