Commit a803e9cf48

Jacob Young <jacobly0@users.noreply.github.com>
2023-05-30 03:47:34
Sema: fix vector comparison and interning of -0
1 parent 66ae42b
Changed files (2)
lib
std
math
src
lib/std/math/big/int.zig
@@ -2158,6 +2158,9 @@ pub const Const = struct {
     pub fn to(self: Const, comptime T: type) ConvertError!T {
         switch (@typeInfo(T)) {
             .Int => |info| {
+                // Make sure -0 is handled correctly.
+                if (self.eqZero()) return 0;
+
                 const UT = std.meta.Int(.unsigned, info.bits);
 
                 if (!self.fitsInTwosComp(info.signedness, info.bits)) {
src/Sema.zig
@@ -34538,10 +34538,13 @@ fn compareScalar(
     rhs: Value,
     ty: Type,
 ) CompileError!bool {
+    const mod = sema.mod;
+    const coerced_lhs = try mod.getCoerced(lhs, ty);
+    const coerced_rhs = try mod.getCoerced(rhs, ty);
     switch (op) {
-        .eq => return sema.valuesEqual(lhs, rhs, ty),
-        .neq => return !(try sema.valuesEqual(lhs, rhs, ty)),
-        else => return Value.compareHeteroAdvanced(lhs, op, rhs, sema.mod, sema),
+        .eq => return sema.valuesEqual(coerced_lhs, coerced_rhs, ty),
+        .neq => return !(try sema.valuesEqual(coerced_lhs, coerced_rhs, ty)),
+        else => return Value.compareHeteroAdvanced(coerced_lhs, op, coerced_rhs, mod, sema),
     }
 }