[libc] Fix the remaining isnan and isinf in tests. (#100969)
Fixes https://github.com/llvm/llvm-project/issues/100964
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ using LIBC_NAMESPACE::testing::tlog;
|
||||
|
||||
TEST_F(LlvmLibcCbrtTest, InDoubleRange) {
|
||||
constexpr uint64_t COUNT = 123'451;
|
||||
uint64_t START = LIBC_NAMESPACE::fputil::FPBits<double>(1.0).uintval();
|
||||
uint64_t STOP = LIBC_NAMESPACE::fputil::FPBits<double>(8.0).uintval();
|
||||
uint64_t START = FPBits(1.0).uintval();
|
||||
uint64_t STOP = FPBits(8.0).uintval();
|
||||
uint64_t STEP = (STOP - START) / COUNT;
|
||||
|
||||
auto test = [&](mpfr::RoundingMode rounding_mode) {
|
||||
@@ -38,12 +38,12 @@ TEST_F(LlvmLibcCbrtTest, InDoubleRange) {
|
||||
|
||||
for (uint64_t i = 0, v = START; i <= COUNT; ++i, v += STEP) {
|
||||
double x = FPBits(v).get_val();
|
||||
if (isnan(x) || isinf(x))
|
||||
if (FPBits(x).is_inf_or_nan())
|
||||
continue;
|
||||
|
||||
double result = LIBC_NAMESPACE::cbrt(x);
|
||||
++total;
|
||||
if (isnan(result) || isinf(result))
|
||||
if (FPBits(result).is_inf_or_nan())
|
||||
continue;
|
||||
|
||||
++tested;
|
||||
|
||||
@@ -27,8 +27,6 @@ TEST(LlvmLibcX86LongDoubleTest, is_nan) {
|
||||
// If exponent has the max value and the implicit bit is 0,
|
||||
// then the number is a NaN for all values of mantissa.
|
||||
bits.set_mantissa(i);
|
||||
long double nan = bits.get_val();
|
||||
ASSERT_NE(static_cast<int>(isnan(nan)), 0);
|
||||
ASSERT_TRUE(bits.is_nan());
|
||||
}
|
||||
|
||||
@@ -38,8 +36,6 @@ TEST(LlvmLibcX86LongDoubleTest, is_nan) {
|
||||
// then the number is a NaN for all non-zero values of mantissa.
|
||||
// Note the initial value of |i| of 1 to avoid a zero mantissa.
|
||||
bits.set_mantissa(i);
|
||||
long double nan = bits.get_val();
|
||||
ASSERT_NE(static_cast<int>(isnan(nan)), 0);
|
||||
ASSERT_TRUE(bits.is_nan());
|
||||
}
|
||||
|
||||
@@ -49,8 +45,6 @@ TEST(LlvmLibcX86LongDoubleTest, is_nan) {
|
||||
// If exponent is non-zero and also not max, and the implicit bit is 0,
|
||||
// then the number is a NaN for all values of mantissa.
|
||||
bits.set_mantissa(i);
|
||||
long double nan = bits.get_val();
|
||||
ASSERT_NE(static_cast<int>(isnan(nan)), 0);
|
||||
ASSERT_TRUE(bits.is_nan());
|
||||
}
|
||||
|
||||
@@ -60,8 +54,6 @@ TEST(LlvmLibcX86LongDoubleTest, is_nan) {
|
||||
// If exponent is non-zero and also not max, and the implicit bit is 1,
|
||||
// then the number is normal value for all values of mantissa.
|
||||
bits.set_mantissa(i);
|
||||
long double valid = bits.get_val();
|
||||
ASSERT_EQ(static_cast<int>(isnan(valid)), 0);
|
||||
ASSERT_FALSE(bits.is_nan());
|
||||
}
|
||||
|
||||
@@ -70,8 +62,6 @@ TEST(LlvmLibcX86LongDoubleTest, is_nan) {
|
||||
for (unsigned int i = 0; i < COUNT; ++i) {
|
||||
// If exponent is zero, then the number is a valid but denormal value.
|
||||
bits.set_mantissa(i);
|
||||
long double valid = bits.get_val();
|
||||
ASSERT_EQ(static_cast<int>(isnan(valid)), 0);
|
||||
ASSERT_FALSE(bits.is_nan());
|
||||
}
|
||||
|
||||
@@ -80,8 +70,6 @@ TEST(LlvmLibcX86LongDoubleTest, is_nan) {
|
||||
for (unsigned int i = 0; i < COUNT; ++i) {
|
||||
// If exponent is zero, then the number is a valid but denormal value.
|
||||
bits.set_mantissa(i);
|
||||
long double valid = bits.get_val();
|
||||
ASSERT_EQ(static_cast<int>(isnan(valid)), 0);
|
||||
ASSERT_FALSE(bits.is_nan());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user