Sema: fix vector comparison and interning of -0

This commit is contained in:
Jacob Young 2023-05-29 21:47:34 -04:00 committed by Andrew Kelley
parent 66ae42bb72
commit a803e9cf48
2 changed files with 9 additions and 3 deletions

View File

@ -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)) {

View File

@ -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),
}
}