[libc] Fix the remaining isnan and isinf in tests. (#100969)

Fixes https://github.com/llvm/llvm-project/issues/100964
This commit is contained in:
lntue
2024-07-29 00:37:01 -04:00
committed by GitHub
parent 5cddc314c8
commit dfdef2cbf7
4 changed files with 22 additions and 28 deletions

View File

@@ -31,21 +31,22 @@ void RemQuoDiff(RemQuoFunc<T> func1, RemQuoFunc<T> func2, const uint8_t *data,
T remainder1 = func1(x, y, &q1);
T remainder2 = func2(x, y, &q2);
if (isnan(remainder1)) {
if (!isnan(remainder2))
LIBC_NAMESPACE::fputil::FPBits<T> bits1(remainder1);
LIBC_NAMESPACE::fputil::FPBits<T> bits2(remainder2);
if (bit1.is_nan()) {
if (!bit2.is_nan())
__builtin_trap();
return;
}
if (isinf(remainder2) != isinf(remainder1))
if (bit1.is_inf() != bit2.is_inf())
__builtin_trap();
// Compare only the 3 LS bits of the quotient.
if ((q1 & 0x7) != (q2 & 0x7))
__builtin_trap();
LIBC_NAMESPACE::fputil::FPBits<T> bits1(remainder1);
LIBC_NAMESPACE::fputil::FPBits<T> bits2(remainder2);
if (bits1.uintval() != bits2.uintval())
__builtin_trap();
}

View File

@@ -118,9 +118,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
__builtin_trap();
// If any result is NaN, all of them should be NaN. We can't use the usual
// comparisons because NaN != NaN.
if (isnan(float_result) ^ isnan(strtof_result))
if (FPBits<float>(float_result).is_nan() !=
FPBits<float>(strtof_result).is_nan())
__builtin_trap();
if (!isnan(float_result) && float_result != strtof_result)
if (!FPBits<float>(float_result).is_nan() && float_result != strtof_result)
__builtin_trap();
mpfr_clear(mpfr_float);
}
@@ -136,10 +137,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
ptrdiff_t strtod_strlen = out_ptr - str_ptr;
if (result_strlen != strtod_strlen)
__builtin_trap();
if (isnan(double_result) ^ isnan(strtod_result) ||
isnan(double_result) ^ isnan(atof_result))
if (FPBits<double>(double_result).is_nan() !=
FPBits<double>(strtod_result).is_nan() ||
FPBits<double>(double_result).is_nan() !=
FPBits<double>(atof_result).is_nan())
__builtin_trap();
if (!isnan(double_result) &&
if (!FPBits<double>(double_result).is_nan() &&
(double_result != strtod_result || double_result != atof_result))
__builtin_trap();
mpfr_clear(mpfr_double);
@@ -156,9 +159,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
ptrdiff_t strtold_strlen = out_ptr - str_ptr;
if (result_strlen != strtold_strlen)
__builtin_trap();
if (isnan(long_double_result) ^ isnan(strtold_result))
if (FPBits<long double>(long_double_result).is_nan() ^
FPBits<long double>(strtold_result).is_nan())
__builtin_trap();
if (!isnan(long_double_result) && long_double_result != strtold_result)
if (!FPBits<long double>(long_double_result).is_nan() &&
long_double_result != strtold_result)
__builtin_trap();
mpfr_clear(mpfr_long_double);
}