[libc] Enable hermetic floating point tests again.
authorTue Ly <lntue@google.com>
Wed, 14 Jun 2023 14:52:23 +0000 (10:52 -0400)
committerTue Ly <lntue@google.com>
Wed, 14 Jun 2023 14:53:35 +0000 (10:53 -0400)
Fixing an issue with LLVM libc's fenv.h defined rounding mode macros
differently from system libc, making get_round() return different values from
fegetround().  Also letting math tests to skip rounding modes that cannot be
set.  This should allow math tests to be run on platforms in which fenv.h is not
implemented yet.

This allows us to re-enable hermatic floating point tests in
https://reviews.llvm.org/D151123 and reverting https://reviews.llvm.org/D152742.

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D152873

41 files changed:
libc/include/llvm-libc-macros/fenv-macros.h
libc/src/__support/FPUtil/FEnvImpl.h
libc/test/UnitTest/CMakeLists.txt
libc/test/UnitTest/FPMatcher.h
libc/test/UnitTest/RoundingModeUtils.cpp
libc/test/UnitTest/RoundingModeUtils.h
libc/test/src/CMakeLists.txt
libc/test/src/__support/FPUtil/CMakeLists.txt
libc/test/src/__support/FPUtil/rounding_mode_test.cpp
libc/test/src/fenv/CMakeLists.txt
libc/test/src/math/SqrtTest.h
libc/test/src/math/exhaustive/acosf_test.cpp
libc/test/src/math/exhaustive/acoshf_test.cpp
libc/test/src/math/exhaustive/asinf_test.cpp
libc/test/src/math/exhaustive/asinhf_test.cpp
libc/test/src/math/exhaustive/atanf_test.cpp
libc/test/src/math/exhaustive/atanhf_test.cpp
libc/test/src/math/exhaustive/cosf_test.cpp
libc/test/src/math/exhaustive/coshf_test.cpp
libc/test/src/math/exhaustive/exp10f_test.cpp
libc/test/src/math/exhaustive/exp2f_test.cpp
libc/test/src/math/exhaustive/expf_test.cpp
libc/test/src/math/exhaustive/expm1f_test.cpp
libc/test/src/math/exhaustive/hypotf_test.cpp
libc/test/src/math/exhaustive/log10f_test.cpp
libc/test/src/math/exhaustive/log1pf_test.cpp
libc/test/src/math/exhaustive/log2f_test.cpp
libc/test/src/math/exhaustive/logf_test.cpp
libc/test/src/math/exhaustive/sincosf_test.cpp
libc/test/src/math/exhaustive/sinf_test.cpp
libc/test/src/math/exhaustive/sinhf_test.cpp
libc/test/src/math/exhaustive/tanf_test.cpp
libc/test/src/math/exhaustive/tanhf_test.cpp
libc/test/src/math/log10_test.cpp
libc/test/src/math/log1p_test.cpp
libc/test/src/math/log2_test.cpp
libc/test/src/math/log_test.cpp
libc/test/src/math/sincosf_test.cpp
libc/test/src/stdio/sprintf_test.cpp
libc/utils/MPFRWrapper/MPFRUtils.h
utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel

index a73ebf41cbb36e600d1fb221eedde93f424c965b..cc0ea344b1702b847ed78b8da75a7960ccd08b29 100644 (file)
 #define FE_ALL_EXCEPT                                                          \
   (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)
 
-#define FE_DOWNWARD 1
-#define FE_TONEAREST 2
-#define FE_TOWARDZERO 4
-#define FE_UPWARD 8
+#define FE_DOWNWARD 0x400
+#define FE_TONEAREST 0
+#define FE_TOWARDZERO 0xC00
+#define FE_UPWARD 0x800
 
 #define FE_DFL_ENV ((fenv_t *)-1)
 
index ee2bd16e821d9ea2fede120974f37a0697c69162..2556f432b02cc13e1d2003689f3f50715ba905d4 100644 (file)
@@ -42,6 +42,8 @@ LIBC_INLINE int clear_except(int) { return 0; }
 
 LIBC_INLINE int test_except(int) { return 0; }
 
+LIBC_INLINE int get_except() { return 0; }
+
 LIBC_INLINE int set_except(int) { return 0; }
 
 LIBC_INLINE int raise_except(int) { return 0; }
@@ -52,7 +54,9 @@ LIBC_INLINE int disable_except(int) { return 0; }
 
 LIBC_INLINE int get_round() { return FE_TONEAREST; }
 
-LIBC_INLINE int set_round(int) { return 0; }
+LIBC_INLINE int set_round(int rounding_mode) {
+  return (rounding_mode == FE_TONEAREST) ? 0 : 1;
+}
 
 LIBC_INLINE int get_env(fenv_t *) { return 0; }
 
index ec8182d88165a3ecc4df61a42527d27ec14f9342..aa081706f50227edbebe710f048aee09bef09d6e 100644 (file)
@@ -110,6 +110,7 @@ add_unittest_framework_library(
     libc.src.__support.FPUtil.fp_bits
     libc.src.__support.FPUtil.fpbits_str
     libc.src.__support.FPUtil.fenv_impl
+    libc.src.__support.FPUtil.rounding_mode
 )
 
 add_unittest_framework_library(
index 549892e8275b576283d0831e50b82e9b06eba506..d8d032b3ef530d08466c2b36b1a3e5e1f0b3d546 100644 (file)
@@ -164,13 +164,17 @@ template <TestCond C, typename T> FPMatcher<T, C> getMatcher(T expectedValue) {
   do {                                                                         \
     using namespace __llvm_libc::fputil::testing;                              \
     ForceRoundingMode __r1(RoundingMode::Nearest);                             \
-    EXPECT_FP_EQ((expected), (actual));                                        \
+    if (__r1.success)                                                          \
+      EXPECT_FP_EQ((expected), (actual));                                      \
     ForceRoundingMode __r2(RoundingMode::Upward);                              \
-    EXPECT_FP_EQ((expected), (actual));                                        \
+    if (__r2.success)                                                          \
+      EXPECT_FP_EQ((expected), (actual));                                      \
     ForceRoundingMode __r3(RoundingMode::Downward);                            \
-    EXPECT_FP_EQ((expected), (actual));                                        \
+    if (__r3.success)                                                          \
+      EXPECT_FP_EQ((expected), (actual));                                      \
     ForceRoundingMode __r4(RoundingMode::TowardZero);                          \
-    EXPECT_FP_EQ((expected), (actual));                                        \
+    if (__r4.success)                                                          \
+      EXPECT_FP_EQ((expected), (actual));                                      \
   } while (0)
 
 #endif // LLVM_LIBC_UTILS_UNITTEST_FPMATCHER_H
index 8cc6834d89edbe0d320ad28fa405e409fcf78979..c6a69fc3f16fc487c126dc1db30fbf86eb982ce0 100644 (file)
@@ -7,6 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "RoundingModeUtils.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/rounding_mode.h"
 
 #include <fenv.h>
 
@@ -34,15 +36,19 @@ int get_fe_rounding(RoundingMode mode) {
 }
 
 ForceRoundingMode::ForceRoundingMode(RoundingMode mode) {
-  old_rounding_mode = fegetround();
+  old_rounding_mode = quick_get_round();
   rounding_mode = get_fe_rounding(mode);
-  if (old_rounding_mode != rounding_mode)
-    fesetround(rounding_mode);
+  if (old_rounding_mode != rounding_mode) {
+    int status = set_round(rounding_mode);
+    success = (status == 0);
+  } else {
+    success = true;
+  }
 }
 
 ForceRoundingMode::~ForceRoundingMode() {
   if (old_rounding_mode != rounding_mode)
-    fesetround(old_rounding_mode);
+    set_round(old_rounding_mode);
 }
 
 } // namespace testing
index ac9f310eebe5a16f38ee37c3fe6ab34caf1a1973..e8611c34b5403376fdc36737cb1b81146391f10c 100644 (file)
@@ -23,6 +23,7 @@ struct ForceRoundingMode {
 
   int old_rounding_mode;
   int rounding_mode;
+  bool success;
 };
 
 template <RoundingMode R> struct ForceRoundingModeTest : ForceRoundingMode {
index 9e6c02c1f9f4b482784f942f8e497ec40c3f6721..52452cd1037dbfbd02505ba76a6d60d42ca2db13 100644 (file)
@@ -1,7 +1,7 @@
 function(add_fp_unittest name)
   cmake_parse_arguments(
     "MATH_UNITTEST"
-    "NEED_MPFR;HERMETIC_TEST_ONLY" # Optional arguments
+    "NEED_MPFR;UNIT_TEST_ONLY;HERMETIC_TEST_ONLY" # Optional arguments
     "" # Single value arguments
     "LINK_LIBRARIES" # Multi-value arguments
     ${ARGN}
@@ -16,6 +16,8 @@ function(add_fp_unittest name)
 
   if(MATH_UNITTEST_HERMETIC_TEST_ONLY)
     set(test_type HERMETIC_TEST_ONLY)
+  elseif(MATH_UNITTEST_UNIT_TEST_ONLY)
+    set(test_type UNIT_TEST_ONLY)
   endif()
   if(MATH_UNITTEST_NEED_MPFR)
     if(MATH_UNITTEST_HERMETIC_TEST_ONLY)
@@ -26,7 +28,7 @@ function(add_fp_unittest name)
   endif()
   list(APPEND MATH_UNITTEST_LINK_LIBRARIES LibcFPTestHelpers)
 
-  add_libc_unittest(
+  add_libc_test(
     ${name}
     ${test_type}
     LINK_LIBRARIES "${MATH_UNITTEST_LINK_LIBRARIES}"
index 9367e2bb40a7acc647668a9664b7b7f2712d5d2e..411b8281470cf17319f3e3c2dc934b0f3d0bc456 100644 (file)
@@ -1,17 +1,15 @@
 add_custom_target(libc-fputil-tests)
 
-if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU)
-  add_fp_unittest(
-    dyadic_float_test
-    NEED_MPFR
-    SUITE
-      libc-fputil-tests
-    SRCS
-      dyadic_float_test.cpp
-    DEPENDS
-      libc.src.__support.FPUtil.dyadic_float
-  )
-endif()
+add_fp_unittest(
+  dyadic_float_test
+  NEED_MPFR
+  SUITE
+    libc-fputil-tests
+  SRCS
+    dyadic_float_test.cpp
+  DEPENDS
+    libc.src.__support.FPUtil.dyadic_float
+)
 
 add_libc_test(
   fpbits_test
@@ -24,14 +22,12 @@ add_libc_test(
     libc.src.__support.FPUtil.fpbits_str
 )
 
-if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU)
-  add_fp_unittest(
-    rounding_mode_test
-    SUITE
-      libc-fputil-tests
-    SRCS
-      rounding_mode_test.cpp
-    DEPENDS
-      libc.src.__support.FPUtil.rounding_mode
-  )
-endif()
+add_fp_unittest(
+  rounding_mode_test
+  SUITE
+    libc-fputil-tests
+  SRCS
+    rounding_mode_test.cpp
+  DEPENDS
+    libc.src.__support.FPUtil.rounding_mode
+)
index 8d3332f142ccf10b325b28089b7ee8e7149c928d..01c1b3c2a9ffaf411d474a5f9d7d4238875c225f 100644 (file)
@@ -19,19 +19,23 @@ TEST(LlvmLibcFEnvImplTest, QuickRoundingUpTest) {
   using __llvm_libc::fputil::fenv_is_round_up;
   {
     ForceRoundingMode __r(RoundingMode::Upward);
-    ASSERT_TRUE(fenv_is_round_up());
+    if (__r.success)
+      ASSERT_TRUE(fenv_is_round_up());
   }
   {
     ForceRoundingMode __r(RoundingMode::Downward);
-    ASSERT_FALSE(fenv_is_round_up());
+    if (__r.success)
+      ASSERT_FALSE(fenv_is_round_up());
   }
   {
     ForceRoundingMode __r(RoundingMode::Nearest);
-    ASSERT_FALSE(fenv_is_round_up());
+    if (__r.success)
+      ASSERT_FALSE(fenv_is_round_up());
   }
   {
     ForceRoundingMode __r(RoundingMode::TowardZero);
-    ASSERT_FALSE(fenv_is_round_up());
+    if (__r.success)
+      ASSERT_FALSE(fenv_is_round_up());
   }
 }
 
@@ -39,19 +43,23 @@ TEST(LlvmLibcFEnvImplTest, QuickRoundingDownTest) {
   using __llvm_libc::fputil::fenv_is_round_down;
   {
     ForceRoundingMode __r(RoundingMode::Upward);
-    ASSERT_FALSE(fenv_is_round_down());
+    if (__r.success)
+      ASSERT_FALSE(fenv_is_round_down());
   }
   {
     ForceRoundingMode __r(RoundingMode::Downward);
-    ASSERT_TRUE(fenv_is_round_down());
+    if (__r.success)
+      ASSERT_TRUE(fenv_is_round_down());
   }
   {
     ForceRoundingMode __r(RoundingMode::Nearest);
-    ASSERT_FALSE(fenv_is_round_down());
+    if (__r.success)
+      ASSERT_FALSE(fenv_is_round_down());
   }
   {
     ForceRoundingMode __r(RoundingMode::TowardZero);
-    ASSERT_FALSE(fenv_is_round_down());
+    if (__r.success)
+      ASSERT_FALSE(fenv_is_round_down());
   }
 }
 
@@ -59,19 +67,23 @@ TEST(LlvmLibcFEnvImplTest, QuickRoundingNearestTest) {
   using __llvm_libc::fputil::fenv_is_round_to_nearest;
   {
     ForceRoundingMode __r(RoundingMode::Upward);
-    ASSERT_FALSE(fenv_is_round_to_nearest());
+    if (__r.success)
+      ASSERT_FALSE(fenv_is_round_to_nearest());
   }
   {
     ForceRoundingMode __r(RoundingMode::Downward);
-    ASSERT_FALSE(fenv_is_round_to_nearest());
+    if (__r.success)
+      ASSERT_FALSE(fenv_is_round_to_nearest());
   }
   {
     ForceRoundingMode __r(RoundingMode::Nearest);
-    ASSERT_TRUE(fenv_is_round_to_nearest());
+    if (__r.success)
+      ASSERT_TRUE(fenv_is_round_to_nearest());
   }
   {
     ForceRoundingMode __r(RoundingMode::TowardZero);
-    ASSERT_FALSE(fenv_is_round_to_nearest());
+    if (__r.success)
+      ASSERT_FALSE(fenv_is_round_to_nearest());
   }
 }
 
@@ -79,19 +91,23 @@ TEST(LlvmLibcFEnvImplTest, QuickRoundingTowardZeroTest) {
   using __llvm_libc::fputil::fenv_is_round_to_zero;
   {
     ForceRoundingMode __r(RoundingMode::Upward);
-    ASSERT_FALSE(fenv_is_round_to_zero());
+    if (__r.success)
+      ASSERT_FALSE(fenv_is_round_to_zero());
   }
   {
     ForceRoundingMode __r(RoundingMode::Downward);
-    ASSERT_FALSE(fenv_is_round_to_zero());
+    if (__r.success)
+      ASSERT_FALSE(fenv_is_round_to_zero());
   }
   {
     ForceRoundingMode __r(RoundingMode::Nearest);
-    ASSERT_FALSE(fenv_is_round_to_zero());
+    if (__r.success)
+      ASSERT_FALSE(fenv_is_round_to_zero());
   }
   {
     ForceRoundingMode __r(RoundingMode::TowardZero);
-    ASSERT_TRUE(fenv_is_round_to_zero());
+    if (__r.success)
+      ASSERT_TRUE(fenv_is_round_to_zero());
   }
 }
 
@@ -99,18 +115,22 @@ TEST(LlvmLibcFEnvImplTest, QuickGetRoundTest) {
   using __llvm_libc::fputil::quick_get_round;
   {
     ForceRoundingMode __r(RoundingMode::Upward);
-    ASSERT_EQ(quick_get_round(), FE_UPWARD);
+    if (__r.success)
+      ASSERT_EQ(quick_get_round(), FE_UPWARD);
   }
   {
     ForceRoundingMode __r(RoundingMode::Downward);
-    ASSERT_EQ(quick_get_round(), FE_DOWNWARD);
+    if (__r.success)
+      ASSERT_EQ(quick_get_round(), FE_DOWNWARD);
   }
   {
     ForceRoundingMode __r(RoundingMode::Nearest);
-    ASSERT_EQ(quick_get_round(), FE_TONEAREST);
+    if (__r.success)
+      ASSERT_EQ(quick_get_round(), FE_TONEAREST);
   }
   {
     ForceRoundingMode __r(RoundingMode::TowardZero);
-    ASSERT_EQ(quick_get_round(), FE_TOWARDZERO);
+    if (__r.success)
+      ASSERT_EQ(quick_get_round(), FE_TOWARDZERO);
   }
 }
index 11179cc88c3800125c44bd53118ef6b009808fe7..d7b9104cf8304a3c6d85928d9708a2f96689d3fd 100644 (file)
@@ -94,6 +94,7 @@ if (NOT (LLVM_USE_SANITIZER OR (${LIBC_TARGET_OS} STREQUAL "windows")
   # and MacOS.
   add_fp_unittest(
     enabled_exceptions_test
+    UNIT_TEST_ONLY
     SUITE
       libc_fenv_unittests
     SRCS
@@ -110,6 +111,7 @@ if (NOT (LLVM_USE_SANITIZER OR (${LIBC_TARGET_OS} STREQUAL "windows")
 
   add_fp_unittest(
     feholdexcept_test
+    UNIT_TEST_ONLY
     SUITE
       libc_fenv_unittests
     SRCS
index dbac32581a58bb43f7ac9fb8f0a78cca16930c58..f73a14ac4c19d363c606366d695fd9d35a57d8b8 100644 (file)
@@ -41,15 +41,15 @@ public:
     for (UIntType mant = 1; mant < HIDDEN_BIT; mant <<= 1) {
       FPBits denormal(T(0.0));
       denormal.set_mantissa(mant);
-
-      test_all_rounding_modes(func, T(denormal));
+      T x = T(denormal);
+      EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sqrt, x, func(x), 0.5);
     }
 
     constexpr UIntType COUNT = 200'001;
     constexpr UIntType STEP = HIDDEN_BIT / COUNT;
     for (UIntType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
       T x = __llvm_libc::cpp::bit_cast<T>(v);
-      test_all_rounding_modes(func, x);
+      EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sqrt, x, func(x), 0.5);
     }
   }
 
@@ -61,27 +61,9 @@ public:
       if (isnan(x) || (x < 0)) {
         continue;
       }
-      test_all_rounding_modes(func, x);
+      EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sqrt, x, func(x), 0.5);
     }
   }
-
-  void test_all_rounding_modes(SqrtFunc func, T x) {
-    mpfr::ForceRoundingMode r1(mpfr::RoundingMode::Nearest);
-    EXPECT_MPFR_MATCH(mpfr::Operation::Sqrt, x, func(x), 0.5,
-                      mpfr::RoundingMode::Nearest);
-
-    mpfr::ForceRoundingMode r2(mpfr::RoundingMode::Upward);
-    EXPECT_MPFR_MATCH(mpfr::Operation::Sqrt, x, func(x), 0.5,
-                      mpfr::RoundingMode::Upward);
-
-    mpfr::ForceRoundingMode r3(mpfr::RoundingMode::Downward);
-    EXPECT_MPFR_MATCH(mpfr::Operation::Sqrt, x, func(x), 0.5,
-                      mpfr::RoundingMode::Downward);
-
-    mpfr::ForceRoundingMode r4(mpfr::RoundingMode::TowardZero);
-    EXPECT_MPFR_MATCH(mpfr::Operation::Sqrt, x, func(x), 0.5,
-                      mpfr::RoundingMode::TowardZero);
-  }
 };
 
 #define LIST_SQRT_TESTS(T, func)                                               \
index c6e15841118ef65ed2e0aed333ad4dd441914c2c..66970744b5daa4782949bd01026fd19662cc2ad8 100644 (file)
@@ -21,6 +21,8 @@ struct LlvmLibcAcosfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
   bool check(uint32_t start, uint32_t stop,
              mpfr::RoundingMode rounding) override {
     mpfr::ForceRoundingMode r(rounding);
+    if (!r.success)
+      return true;
     uint32_t bits = start;
     bool result = true;
     do {
index 01f6e2db1867101d07641abafe6aa7dac9dc1719..6f1196292e278b837a471b9f32b3bdc9acea93aa 100644 (file)
@@ -21,6 +21,8 @@ struct LlvmLibcAcoshfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
   bool check(uint32_t start, uint32_t stop,
              mpfr::RoundingMode rounding) override {
     mpfr::ForceRoundingMode r(rounding);
+    if (!r.success)
+      return true;
     uint32_t bits = start;
     bool result = true;
     do {
index 6baa03ad33cd98c306f69bf5d5c8a1201af03e9b..4296259f08211def35970287fb5db98134fb3345 100644 (file)
@@ -21,6 +21,8 @@ struct LlvmLibcAsinfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
   bool check(uint32_t start, uint32_t stop,
              mpfr::RoundingMode rounding) override {
     mpfr::ForceRoundingMode r(rounding);
+    if (!r.success)
+      return true;
     uint32_t bits = start;
     bool result = true;
     do {
index 3fe506f1189be21304f242140ccaeeb3336eeb44..296e42c0d25d551c3e7fd840d750cf072a2a30d6 100644 (file)
@@ -21,6 +21,8 @@ struct LlvmLibcAsinhfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
   bool check(uint32_t start, uint32_t stop,
              mpfr::RoundingMode rounding) override {
     mpfr::ForceRoundingMode r(rounding);
+    if (!r.success)
+      return true;
     uint32_t bits = start;
     bool result = true;
     do {
index b4bb112c12475adfd29e8a0297a5c0b9619d94a9..c2a1055ac4edf95c198c5425d418447a5ef41e05 100644 (file)
@@ -21,6 +21,8 @@ struct LlvmLibcAtanfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
   bool check(uint32_t start, uint32_t stop,
              mpfr::RoundingMode rounding) override {
     mpfr::ForceRoundingMode r(rounding);
+    if (!r.success)
+      return true;
     uint32_t bits = start;
     bool result = true;
     do {
index 9e0f49f66c0a7d60e33f3d6f0c670f40f8cadc2b..b4746a8349c625669490903bf11cf0b6dab8db02 100644 (file)
@@ -21,6 +21,8 @@ struct LlvmLibcAtanhfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
   bool check(uint32_t start, uint32_t stop,
              mpfr::RoundingMode rounding) override {
     mpfr::ForceRoundingMode r(rounding);
+    if (!r.success)
+      return true;
     uint32_t bits = start;
     bool result = true;
     do {
index b78c24664bad2b04132982ec3e817c042efdb92a..67bd0c51408431a671fbed59079ecc7b0f7a413b 100644 (file)
@@ -22,6 +22,8 @@ struct LlvmLibcCosfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
   bool check(uint32_t start, uint32_t stop,
              mpfr::RoundingMode rounding) override {
     mpfr::ForceRoundingMode r(rounding);
+    if (!r.success)
+      return true;
     uint32_t bits = start;
     bool result = true;
     do {
index bff971bf5d03d3d9b5a155893d6029cbaf0c46c3..ce7a000d98477a76f231f4c3e5625efc8f340ca6 100644 (file)
@@ -22,6 +22,8 @@ struct LlvmLibcCoshfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
   bool check(uint32_t start, uint32_t stop,
              mpfr::RoundingMode rounding) override {
     mpfr::ForceRoundingMode r(rounding);
+    if (!r.success)
+      return true;
     uint32_t bits = start;
     bool result = true;
     do {
index 4b26dfa256aa543df0fcdb2b373a7b9d25f08daf..67f9514b358a90f720c7920a136dd8a4371b0938 100644 (file)
@@ -22,6 +22,8 @@ struct LlvmLibcExp10fExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
   bool check(uint32_t start, uint32_t stop,
              mpfr::RoundingMode rounding) override {
     mpfr::ForceRoundingMode r(rounding);
+    if (!r.success)
+      return true;
     uint32_t bits = start;
     bool result = true;
     do {
index 49156f33881436f304ca5aeeffe0955a45781080..de8b230e9f91b82f73b36a036f86ae8b82cd980a 100644 (file)
@@ -20,6 +20,8 @@ struct LlvmLibcExp2fExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
   bool check(uint32_t start, uint32_t stop,
              mpfr::RoundingMode rounding) override {
     mpfr::ForceRoundingMode r(rounding);
+    if (!r.success)
+      return true;
     uint32_t bits = start;
     bool result = true;
     do {
index 36f3044ee0908c70aa3c86d5499c81520883638a..64bf814229b39699d17c66c1faee99a62514aa1d 100644 (file)
@@ -22,6 +22,8 @@ struct LlvmLibcExpfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
   bool check(uint32_t start, uint32_t stop,
              mpfr::RoundingMode rounding) override {
     mpfr::ForceRoundingMode r(rounding);
+    if (!r.success)
+      return true;
     uint32_t bits = start;
     bool result = true;
     do {
index 0434a08e52903d30aea1fb24c65512d357b5247a..42225ea804b6aad02e5f6f1df0ff0c2c3cdd3429 100644 (file)
@@ -21,6 +21,8 @@ namespace mpfr = __llvm_libc::testing::mpfr;
 struct LlvmLibcExpm1fExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
   bool check(uint32_t start, uint32_t stop,
              mpfr::RoundingMode rounding) override {
+    if (!r.success)
+      return true;
     mpfr::ForceRoundingMode r(rounding);
     uint32_t bits = stop;
     bool result = true;
index c8446688dc0523224601356da8bf35c4d4757541..8463f88c7f26cf44e664482bc247c84487b321df 100644 (file)
@@ -25,6 +25,8 @@ struct LlvmLibcHypotfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
     constexpr uint32_t Y_STOP = (48U + 127U) << 23;
 
     mpfr::ForceRoundingMode r(rounding);
+    if (!r.success)
+      return true;
     uint32_t xbits = start;
     bool result = true;
     do {
index 0cdfc3e96449a51a13b1840b9ab70edca68d3e9e..58f6ecb513a0fd9da97b5977b8088b51868aa406 100644 (file)
@@ -20,6 +20,8 @@ struct LlvmLibcLog10fExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
   bool check(uint32_t start, uint32_t stop,
              mpfr::RoundingMode rounding) override {
     mpfr::ForceRoundingMode r(rounding);
+    if (!r.success)
+      return true;
     uint32_t bits = start;
     bool result = true;
     do {
index ab3bd27bdd8c3623a97df7095882e112c0235a3d..88944d5c7f4998515a15d7f3758c931ae559b21f 100644 (file)
@@ -20,6 +20,8 @@ struct LlvmLibcLog1pfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
   bool check(uint32_t start, uint32_t stop,
              mpfr::RoundingMode rounding) override {
     mpfr::ForceRoundingMode r(rounding);
+    if (!r.success)
+      return true;
     uint32_t bits = start;
     bool result = true;
     do {
index c86b9995ef90af935c25ccbcf001f85e7a1f7ad4..fb674ffa7cb0779cdf9fe98d7030e6a9a85a76a8 100644 (file)
@@ -20,6 +20,8 @@ struct LlvmLibcLog2fExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
   bool check(uint32_t start, uint32_t stop,
              mpfr::RoundingMode rounding) override {
     mpfr::ForceRoundingMode r(rounding);
+    if (!r.success)
+      return true;
     uint32_t bits = start;
     bool result = true;
     do {
index c9327985e8f1511cc6f07420eec91ef5fd954cc2..e67d6ce74ed6ff3f44b90506a2bdd80048fca4c5 100644 (file)
@@ -20,6 +20,8 @@ struct LlvmLibcLogfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
   bool check(uint32_t start, uint32_t stop,
              mpfr::RoundingMode rounding) override {
     mpfr::ForceRoundingMode r(rounding);
+    if (!r.success)
+      return true;
     uint32_t bits = start;
     bool result = true;
     do {
index 6a1006f3d5d5418423f55532c36452c7decfd485..ecda2cbbf57f824b3b2da832a3d059c2886929d4 100644 (file)
@@ -22,6 +22,8 @@ struct LlvmLibcSinCosfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
   bool check(uint32_t start, uint32_t stop,
              mpfr::RoundingMode rounding) override {
     mpfr::ForceRoundingMode r(rounding);
+    if (!r.success)
+      return true;
     uint32_t bits = start;
     bool result = true;
     do {
index 67188034c057bafd3ed2f8a9d8cc052e7bf2966d..4749ef68636b85681ab2fed2642744e0aada0889 100644 (file)
@@ -22,6 +22,8 @@ struct LlvmLibcSinfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
   bool check(uint32_t start, uint32_t stop,
              mpfr::RoundingMode rounding) override {
     mpfr::ForceRoundingMode r(rounding);
+    if (!r.success)
+      return true;
     uint32_t bits = start;
     bool result = true;
     do {
index 05328ecf2a7af1024373e5426517f22c0e47c0e6..a2fa540a98907539644a6c4dd86e5a2e38099daf 100644 (file)
@@ -22,6 +22,8 @@ struct LlvmLibcSinhfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
   bool check(uint32_t start, uint32_t stop,
              mpfr::RoundingMode rounding) override {
     mpfr::ForceRoundingMode r(rounding);
+    if (!r.success)
+      return true;
     uint32_t bits = start;
     bool result = true;
     do {
index a189cb897b74d30b47cc30f2da5007dc165305e1..3597517de3d9b3f11580b3cd294c69fb942dd5c1 100644 (file)
@@ -25,6 +25,8 @@ struct LlvmLibcTanfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
   bool check(uint32_t start, uint32_t stop,
              mpfr::RoundingMode rounding) override {
     mpfr::ForceRoundingMode r(rounding);
+    if (!r.success)
+      return true;
     uint32_t bits = start;
     bool result = true;
     int tol = TOLERANCE;
index 0a0607a6a1875fd33eb2212d932b819e243becf2..c7bb4e8e112e324f450a5c2dcb81818c2c3c6aa3 100644 (file)
@@ -21,6 +21,8 @@ struct LlvmLibcTanhfExhaustiveTest : public LlvmLibcExhaustiveTest<uint32_t> {
   bool check(uint32_t start, uint32_t stop,
              mpfr::RoundingMode rounding) override {
     mpfr::ForceRoundingMode r(rounding);
+    if (!r.success)
+      return true;
     uint32_t bits = start;
     bool result = true;
     do {
index bd50f57bfcefb85f2a95358861d2e7743d3468fc..ea9d212b054626830a0fd60b604a19ed98ec0cf6 100644 (file)
@@ -87,6 +87,8 @@ TEST(LlvmLibcLog10Test, InDoubleRange) {
 
   auto test = [&](mpfr::RoundingMode rounding_mode) {
     mpfr::ForceRoundingMode __r(rounding_mode);
+    if (!__r.success)
+      return;
     uint64_t fails = 0;
     uint64_t count = 0;
     uint64_t cc = 0;
index f57b4f98c66bb2750f7da16e6c4846fc94253ac4..c128c5e6c918f40d125fdc38782ed8f60c5256bd 100644 (file)
@@ -86,6 +86,9 @@ TEST(LlvmLibcLog1pTest, InDoubleRange) {
   auto test = [&](uint64_t start, uint64_t stop,
                   mpfr::RoundingMode rounding_mode) {
     mpfr::ForceRoundingMode __r(rounding_mode);
+    if (!__r.success)
+      return;
+
     uint64_t fails = 0;
     uint64_t count = 0;
     uint64_t cc = 0;
index dfc56ff2dcf44974da728b68cb83edd62d50efb4..c4756875d6a54b318b049d627f1da5db842e4086 100644 (file)
@@ -87,6 +87,9 @@ TEST(LlvmLibcLog2Test, InDoubleRange) {
 
   auto test = [&](mpfr::RoundingMode rounding_mode) {
     mpfr::ForceRoundingMode __r(rounding_mode);
+    if (!__r.success)
+      return;
+
     uint64_t fails = 0;
     uint64_t count = 0;
     uint64_t cc = 0;
index 230deffedddb8886d175684c40d75978d80248d3..5b662534bbf580e1b2f1188f700f03ce212cc9a7 100644 (file)
@@ -87,6 +87,9 @@ TEST(LlvmLibcLogTest, InDoubleRange) {
 
   auto test = [&](mpfr::RoundingMode rounding_mode) {
     mpfr::ForceRoundingMode __r(rounding_mode);
+    if (!__r.success)
+      return;
+
     uint64_t fails = 0;
     uint64_t count = 0;
     uint64_t cc = 0;
index 1c1d878c7db07db7c75394709c22cfa807b14b62..3a5bdd12fbc38a7778598293cd3c079005d4e1b1 100644 (file)
@@ -61,32 +61,40 @@ TEST(LlvmLibcSinCosfTest, SpecialNumbers) {
     namespace mpfr = __llvm_libc::testing::mpfr;                               \
                                                                                \
     mpfr::ForceRoundingMode __r1(mpfr::RoundingMode::Nearest);                 \
-    __llvm_libc::sincosf(input, &sin, &cos);                                   \
-    EXPECT_MPFR_MATCH(mpfr::Operation::Sin, input, sin, 0.5,                   \
-                      mpfr::RoundingMode::Nearest);                            \
-    EXPECT_MPFR_MATCH(mpfr::Operation::Cos, input, cos, 0.5,                   \
-                      mpfr::RoundingMode::Nearest);                            \
+    if (__r1.success) {                                                        \
+      __llvm_libc::sincosf(input, &sin, &cos);                                 \
+      EXPECT_MPFR_MATCH(mpfr::Operation::Sin, input, sin, 0.5,                 \
+                        mpfr::RoundingMode::Nearest);                          \
+      EXPECT_MPFR_MATCH(mpfr::Operation::Cos, input, cos, 0.5,                 \
+                        mpfr::RoundingMode::Nearest);                          \
+    }                                                                          \
                                                                                \
     mpfr::ForceRoundingMode __r2(mpfr::RoundingMode::Upward);                  \
-    __llvm_libc::sincosf(input, &sin, &cos);                                   \
-    EXPECT_MPFR_MATCH(mpfr::Operation::Sin, input, sin, 0.5,                   \
-                      mpfr::RoundingMode::Upward);                             \
-    EXPECT_MPFR_MATCH(mpfr::Operation::Cos, input, cos, 0.5,                   \
-                      mpfr::RoundingMode::Upward);                             \
+    if (__r2.success) {                                                        \
+      __llvm_libc::sincosf(input, &sin, &cos);                                 \
+      EXPECT_MPFR_MATCH(mpfr::Operation::Sin, input, sin, 0.5,                 \
+                        mpfr::RoundingMode::Upward);                           \
+      EXPECT_MPFR_MATCH(mpfr::Operation::Cos, input, cos, 0.5,                 \
+                        mpfr::RoundingMode::Upward);                           \
+    }                                                                          \
                                                                                \
     mpfr::ForceRoundingMode __r3(mpfr::RoundingMode::Downward);                \
-    __llvm_libc::sincosf(input, &sin, &cos);                                   \
-    EXPECT_MPFR_MATCH(mpfr::Operation::Sin, input, sin, 0.5,                   \
-                      mpfr::RoundingMode::Downward);                           \
-    EXPECT_MPFR_MATCH(mpfr::Operation::Cos, input, cos, 0.5,                   \
-                      mpfr::RoundingMode::Downward);                           \
+    if (__r3.success) {                                                        \
+      __llvm_libc::sincosf(input, &sin, &cos);                                 \
+      EXPECT_MPFR_MATCH(mpfr::Operation::Sin, input, sin, 0.5,                 \
+                        mpfr::RoundingMode::Downward);                         \
+      EXPECT_MPFR_MATCH(mpfr::Operation::Cos, input, cos, 0.5,                 \
+                        mpfr::RoundingMode::Downward);                         \
+    }                                                                          \
                                                                                \
     mpfr::ForceRoundingMode __r4(mpfr::RoundingMode::TowardZero);              \
-    __llvm_libc::sincosf(input, &sin, &cos);                                   \
-    EXPECT_MPFR_MATCH(mpfr::Operation::Sin, input, sin, 0.5,                   \
-                      mpfr::RoundingMode::TowardZero);                         \
-    EXPECT_MPFR_MATCH(mpfr::Operation::Cos, input, cos, 0.5,                   \
-                      mpfr::RoundingMode::TowardZero);                         \
+    if (__r4.success) {                                                        \
+      __llvm_libc::sincosf(input, &sin, &cos);                                 \
+      EXPECT_MPFR_MATCH(mpfr::Operation::Sin, input, sin, 0.5,                 \
+                        mpfr::RoundingMode::TowardZero);                       \
+      EXPECT_MPFR_MATCH(mpfr::Operation::Cos, input, cos, 0.5,                 \
+                        mpfr::RoundingMode::TowardZero);                       \
+    }                                                                          \
   }
 
 TEST(LlvmLibcSinCosfTest, InFloatRange) {
index 9fb770533404624a840557fb8d64fd00a663f8b6..e5552742207e4eaf0cb804ba7da9f7c8d98edac8 100644 (file)
@@ -24,6 +24,9 @@ protected:
   int written;
 };
 
+using __llvm_libc::fputil::testing::ForceRoundingMode;
+using __llvm_libc::fputil::testing::RoundingMode;
+
 // Subtract 1 from sizeof(expected_str) to account for the null byte.
 #define ASSERT_STREQ_LEN(actual_written, actual_str, expected_str)             \
   EXPECT_EQ(actual_written, static_cast<int>(sizeof(expected_str) - 1));       \
@@ -505,8 +508,7 @@ TEST(LlvmLibcSPrintfTest, OctConv) {
 #ifndef LIBC_COPT_PRINTF_DISABLE_FLOAT
 
 TEST_F(LlvmLibcSPrintfTest, FloatHexExpConv) {
-  __llvm_libc::fputil::testing::ForceRoundingMode r(
-      __llvm_libc::fputil::testing::RoundingMode::Nearest);
+  ForceRoundingMode r(RoundingMode::Nearest);
   double inf = __llvm_libc::fputil::FPBits<double>::inf().get_val();
   double nan = __llvm_libc::fputil::FPBits<double>::build_nan(1);
 
@@ -705,10 +707,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatHexExpConv) {
 
   // Rounding Mode Tests.
 
-  {
-    __llvm_libc::fputil::testing::ForceRoundingMode r(
-        __llvm_libc::fputil::testing::RoundingMode::Nearest);
-
+  if (ForceRoundingMode r(RoundingMode::Nearest); r.success) {
     written = __llvm_libc::sprintf(buff, "%.1a", 0x1.08p0);
     ASSERT_STREQ_LEN(written, buff, "0x1.0p+0");
 
@@ -734,10 +733,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatHexExpConv) {
     ASSERT_STREQ_LEN(written, buff, "-0x1.1p+0");
   }
 
-  {
-    __llvm_libc::fputil::testing::ForceRoundingMode r(
-        __llvm_libc::fputil::testing::RoundingMode::Upward);
-
+  if (ForceRoundingMode r(RoundingMode::Upward); r.success) {
     written = __llvm_libc::sprintf(buff, "%.1a", 0x1.08p0);
     ASSERT_STREQ_LEN(written, buff, "0x1.1p+0");
 
@@ -763,10 +759,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatHexExpConv) {
     ASSERT_STREQ_LEN(written, buff, "-0x1.1p+0");
   }
 
-  {
-    __llvm_libc::fputil::testing::ForceRoundingMode r(
-        __llvm_libc::fputil::testing::RoundingMode::Downward);
-
+  if (ForceRoundingMode r(RoundingMode::Downward); r.success) {
     written = __llvm_libc::sprintf(buff, "%.1a", 0x1.08p0);
     ASSERT_STREQ_LEN(written, buff, "0x1.0p+0");
 
@@ -792,10 +785,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatHexExpConv) {
     ASSERT_STREQ_LEN(written, buff, "-0x1.2p+0");
   }
 
-  {
-    __llvm_libc::fputil::testing::ForceRoundingMode r(
-        __llvm_libc::fputil::testing::RoundingMode::TowardZero);
-
+  if (ForceRoundingMode r(RoundingMode::TowardZero); r.success) {
     written = __llvm_libc::sprintf(buff, "%.1a", 0x1.08p0);
     ASSERT_STREQ_LEN(written, buff, "0x1.0p+0");
 
@@ -866,8 +856,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatHexExpConv) {
 }
 
 TEST_F(LlvmLibcSPrintfTest, FloatDecimalConv) {
-  __llvm_libc::fputil::testing::ForceRoundingMode r(
-      __llvm_libc::fputil::testing::RoundingMode::Nearest);
+  ForceRoundingMode r(RoundingMode::Nearest);
   double inf = __llvm_libc::fputil::FPBits<double>::inf().get_val();
   double nan = __llvm_libc::fputil::FPBits<double>::build_nan(1);
 
@@ -1340,10 +1329,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatDecimalConv) {
 
   // Rounding Mode Tests.
 
-  {
-    __llvm_libc::fputil::testing::ForceRoundingMode r(
-        __llvm_libc::fputil::testing::RoundingMode::Nearest);
-
+  if (ForceRoundingMode r(RoundingMode::Nearest); r.success) {
     written = __llvm_libc::sprintf(buff, "%.1f", 1.75);
     ASSERT_STREQ_LEN(written, buff, "1.8");
 
@@ -1381,10 +1367,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatDecimalConv) {
     ASSERT_STREQ_LEN(written, buff, "-1.9");
   }
 
-  {
-    __llvm_libc::fputil::testing::ForceRoundingMode r(
-        __llvm_libc::fputil::testing::RoundingMode::Upward);
-
+  if (ForceRoundingMode r(RoundingMode::Upward); r.success) {
     written = __llvm_libc::sprintf(buff, "%.1f", 1.75);
     ASSERT_STREQ_LEN(written, buff, "1.8");
 
@@ -1422,10 +1405,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatDecimalConv) {
     ASSERT_STREQ_LEN(written, buff, "-1.8");
   }
 
-  {
-    __llvm_libc::fputil::testing::ForceRoundingMode r(
-        __llvm_libc::fputil::testing::RoundingMode::Downward);
-
+  if (ForceRoundingMode r(RoundingMode::Downward); r.success) {
     written = __llvm_libc::sprintf(buff, "%.1f", 1.75);
     ASSERT_STREQ_LEN(written, buff, "1.7");
 
@@ -1463,10 +1443,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatDecimalConv) {
     ASSERT_STREQ_LEN(written, buff, "-1.9");
   }
 
-  {
-    __llvm_libc::fputil::testing::ForceRoundingMode r(
-        __llvm_libc::fputil::testing::RoundingMode::TowardZero);
-
+  if (ForceRoundingMode r(RoundingMode::TowardZero); r.success) {
     written = __llvm_libc::sprintf(buff, "%.1f", 1.75);
     ASSERT_STREQ_LEN(written, buff, "1.7");
 
@@ -1572,8 +1549,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatDecimalConv) {
 }
 
 TEST_F(LlvmLibcSPrintfTest, FloatExponentConv) {
-  __llvm_libc::fputil::testing::ForceRoundingMode r(
-      __llvm_libc::fputil::testing::RoundingMode::Nearest);
+  ForceRoundingMode r(RoundingMode::Nearest);
   double inf = __llvm_libc::fputil::FPBits<double>::inf().get_val();
   double nan = __llvm_libc::fputil::FPBits<double>::build_nan(1);
 
@@ -1926,10 +1902,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatExponentConv) {
 
   // Rounding Mode Tests.
 
-  {
-    __llvm_libc::fputil::testing::ForceRoundingMode r(
-        __llvm_libc::fputil::testing::RoundingMode::Nearest);
-
+  if (ForceRoundingMode r(RoundingMode::Nearest); r.success) {
     written = __llvm_libc::sprintf(buff, "%.1e", 1.75);
     ASSERT_STREQ_LEN(written, buff, "1.8e+00");
 
@@ -1967,10 +1940,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatExponentConv) {
     ASSERT_STREQ_LEN(written, buff, "-1.9e+00");
   }
 
-  {
-    __llvm_libc::fputil::testing::ForceRoundingMode r(
-        __llvm_libc::fputil::testing::RoundingMode::Upward);
-
+  if (ForceRoundingMode r(RoundingMode::Upward); r.success) {
     written = __llvm_libc::sprintf(buff, "%.1e", 1.75);
     ASSERT_STREQ_LEN(written, buff, "1.8e+00");
 
@@ -2008,10 +1978,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatExponentConv) {
     ASSERT_STREQ_LEN(written, buff, "-1.8e+00");
   }
 
-  {
-    __llvm_libc::fputil::testing::ForceRoundingMode r(
-        __llvm_libc::fputil::testing::RoundingMode::Downward);
-
+  if (ForceRoundingMode r(RoundingMode::Downward); r.success) {
     written = __llvm_libc::sprintf(buff, "%.1e", 1.75);
     ASSERT_STREQ_LEN(written, buff, "1.7e+00");
 
@@ -2049,10 +2016,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatExponentConv) {
     ASSERT_STREQ_LEN(written, buff, "-1.9e+00");
   }
 
-  {
-    __llvm_libc::fputil::testing::ForceRoundingMode r(
-        __llvm_libc::fputil::testing::RoundingMode::TowardZero);
-
+  if (ForceRoundingMode r(RoundingMode::TowardZero); r.success) {
     written = __llvm_libc::sprintf(buff, "%.1e", 1.75);
     ASSERT_STREQ_LEN(written, buff, "1.7e+00");
 
@@ -2167,8 +2131,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatExponentConv) {
 }
 
 TEST_F(LlvmLibcSPrintfTest, FloatAutoConv) {
-  __llvm_libc::fputil::testing::ForceRoundingMode r(
-      __llvm_libc::fputil::testing::RoundingMode::Nearest);
+  ForceRoundingMode r(RoundingMode::Nearest);
   double inf = __llvm_libc::fputil::FPBits<double>::inf().get_val();
   double nan = __llvm_libc::fputil::FPBits<double>::build_nan(1);
 
@@ -2545,10 +2508,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatAutoConv) {
 
   // Rounding Mode Tests.
 
-  {
-    __llvm_libc::fputil::testing::ForceRoundingMode r(
-        __llvm_libc::fputil::testing::RoundingMode::Nearest);
-
+  if (ForceRoundingMode r(RoundingMode::Nearest); r.success) {
     written = __llvm_libc::sprintf(buff, "%.2g", 1.75);
     ASSERT_STREQ_LEN(written, buff, "1.8");
 
@@ -2586,10 +2546,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatAutoConv) {
     ASSERT_STREQ_LEN(written, buff, "-1.9");
   }
 
-  {
-    __llvm_libc::fputil::testing::ForceRoundingMode r(
-        __llvm_libc::fputil::testing::RoundingMode::Upward);
-
+  if (ForceRoundingMode r(RoundingMode::Upward); r.success) {
     written = __llvm_libc::sprintf(buff, "%.2g", 1.75);
     ASSERT_STREQ_LEN(written, buff, "1.8");
 
@@ -2627,10 +2584,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatAutoConv) {
     ASSERT_STREQ_LEN(written, buff, "-1.8");
   }
 
-  {
-    __llvm_libc::fputil::testing::ForceRoundingMode r(
-        __llvm_libc::fputil::testing::RoundingMode::Downward);
-
+  if (ForceRoundingMode r(RoundingMode::Downward); r.success) {
     written = __llvm_libc::sprintf(buff, "%.2g", 1.75);
     ASSERT_STREQ_LEN(written, buff, "1.7");
 
@@ -2668,10 +2622,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatAutoConv) {
     ASSERT_STREQ_LEN(written, buff, "-1.9");
   }
 
-  {
-    __llvm_libc::fputil::testing::ForceRoundingMode r(
-        __llvm_libc::fputil::testing::RoundingMode::TowardZero);
-
+  if (ForceRoundingMode r(RoundingMode::TowardZero); r.success) {
     written = __llvm_libc::sprintf(buff, "%.2g", 1.75);
     ASSERT_STREQ_LEN(written, buff, "1.7");
 
index 242bc2bcc1a17ab0fdd72d4abf249c98a47c2dcb..968d05d18a9e32564bb50a6e9838b28a8c3f9cb9 100644 (file)
@@ -354,17 +354,21 @@ template <typename T> bool round_to_long(T x, RoundingMode mode, long &result);
   {                                                                            \
     namespace mpfr = __llvm_libc::testing::mpfr;                               \
     mpfr::ForceRoundingMode __r1(mpfr::RoundingMode::Nearest);                 \
-    EXPECT_MPFR_MATCH(op, input, match_value, ulp_tolerance,                   \
-                      mpfr::RoundingMode::Nearest);                            \
+    if (__r1.success)                                                          \
+      EXPECT_MPFR_MATCH(op, input, match_value, ulp_tolerance,                 \
+                        mpfr::RoundingMode::Nearest);                          \
     mpfr::ForceRoundingMode __r2(mpfr::RoundingMode::Upward);                  \
-    EXPECT_MPFR_MATCH(op, input, match_value, ulp_tolerance,                   \
-                      mpfr::RoundingMode::Upward);                             \
+    if (__r2.success)                                                          \
+      EXPECT_MPFR_MATCH(op, input, match_value, ulp_tolerance,                 \
+                        mpfr::RoundingMode::Upward);                           \
     mpfr::ForceRoundingMode __r3(mpfr::RoundingMode::Downward);                \
-    EXPECT_MPFR_MATCH(op, input, match_value, ulp_tolerance,                   \
-                      mpfr::RoundingMode::Downward);                           \
+    if (__r3.success)                                                          \
+      EXPECT_MPFR_MATCH(op, input, match_value, ulp_tolerance,                 \
+                        mpfr::RoundingMode::Downward);                         \
     mpfr::ForceRoundingMode __r4(mpfr::RoundingMode::TowardZero);              \
-    EXPECT_MPFR_MATCH(op, input, match_value, ulp_tolerance,                   \
-                      mpfr::RoundingMode::TowardZero);                         \
+    if (__r4.success)                                                          \
+      EXPECT_MPFR_MATCH(op, input, match_value, ulp_tolerance,                 \
+                        mpfr::RoundingMode::TowardZero);                       \
   }
 
 #define TEST_MPFR_MATCH_ROUNDING_SILENTLY(op, input, match_value,              \
@@ -393,17 +397,21 @@ template <typename T> bool round_to_long(T x, RoundingMode mode, long &result);
   {                                                                            \
     namespace mpfr = __llvm_libc::testing::mpfr;                               \
     mpfr::ForceRoundingMode __r1(mpfr::RoundingMode::Nearest);                 \
-    ASSERT_MPFR_MATCH(op, input, match_value, ulp_tolerance,                   \
-                      mpfr::RoundingMode::Nearest);                            \
+    if (__r1.success)                                                          \
+      ASSERT_MPFR_MATCH(op, input, match_value, ulp_tolerance,                 \
+                        mpfr::RoundingMode::Nearest);                          \
     mpfr::ForceRoundingMode __r2(mpfr::RoundingMode::Upward);                  \
-    ASSERT_MPFR_MATCH(op, input, match_value, ulp_tolerance,                   \
-                      mpfr::RoundingMode::Upward);                             \
+    if (__r2.success)                                                          \
+      ASSERT_MPFR_MATCH(op, input, match_value, ulp_tolerance,                 \
+                        mpfr::RoundingMode::Upward);                           \
     mpfr::ForceRoundingMode __r3(mpfr::RoundingMode::Downward);                \
-    ASSERT_MPFR_MATCH(op, input, match_value, ulp_tolerance,                   \
-                      mpfr::RoundingMode::Downward);                           \
+    if (__r3.success)                                                          \
+      ASSERT_MPFR_MATCH(op, input, match_value, ulp_tolerance,                 \
+                        mpfr::RoundingMode::Downward);                         \
     mpfr::ForceRoundingMode __r4(mpfr::RoundingMode::TowardZero);              \
-    ASSERT_MPFR_MATCH(op, input, match_value, ulp_tolerance,                   \
-                      mpfr::RoundingMode::TowardZero);                         \
+    if (__r4.success)                                                          \
+      ASSERT_MPFR_MATCH(op, input, match_value, ulp_tolerance,                 \
+                        mpfr::RoundingMode::TowardZero);                       \
   }
 
 #endif // LLVM_LIBC_UTILS_TESTUTILS_MPFRUTILS_H
index 059c988efd1c7b8501d7c5013628663840baba06..395664eab8f643933ba1989ad3fa7a03db42897c 100644 (file)
@@ -47,6 +47,7 @@ cc_library(
         "//libc:__support_cpp_type_traits",
         "//libc:__support_fputil_fp_bits",
         "//libc:__support_fputil_fpbits_str",
+        "//libc:__support_fputil_rounding_mode",
         "//libc:__support_macros_properties_architectures",
         "//libc:__support_stringutil",
         "//libc:__support_uint128",
@@ -77,6 +78,7 @@ cc_library(
         "//libc:__support_fputil_fenv_impl",
         "//libc:__support_fputil_fp_bits",
         "//libc:__support_fputil_fpbits_str",
+        "//libc:__support_fputil_rounding_mode",
         "//libc:libc_root",
     ],
 )