Sema: check for NaNs in cmp (#10760)

This commit is contained in:
Mateusz Radomski 2022-02-04 06:58:27 +01:00 committed by GitHub
parent 0893326e0e
commit 1b6a1e691f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View file

@ -15816,6 +15816,13 @@ fn cmpNumeric(
if (lhs_val.isUndef() or rhs_val.isUndef()) {
return sema.addConstUndef(Type.bool);
}
if (lhs_val.isNan() or rhs_val.isNan()) {
if (op == std.math.CompareOperator.neq) {
return Air.Inst.Ref.bool_true;
} else {
return Air.Inst.Ref.bool_false;
}
}
if (Value.compareHetero(lhs_val, op, rhs_val)) {
return Air.Inst.Ref.bool_true;
} else {

View file

@ -979,18 +979,16 @@ test "vector integer addition" {
}
test "NaN comparison" {
if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
try testNanEqNan(f16);
try testNanEqNan(f32);
try testNanEqNan(f64);
try testNanEqNan(f128);
if (has_f80_rt) try testNanEqNan(f80);
if (has_f80_rt and (builtin.zig_backend == .stage1)) try testNanEqNan(f80); // TODO
comptime try testNanEqNan(f16);
comptime try testNanEqNan(f32);
comptime try testNanEqNan(f64);
comptime try testNanEqNan(f128);
// comptime try testNanEqNan(f80);
// comptime try testNanEqNan(f80); // TODO
}
fn testNanEqNan(comptime F: type) !void {