[libc-commits] [libc] [libc] Add missing functions in FEnvImpl.h under LIBC_MATH_USE_SYSTEM_FENV config. (PR #211303)

via libc-commits libc-commits at lists.llvm.org
Wed Jul 22 14:59:46 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: lntue

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/211303.diff


14 Files Affected:

- (modified) libc/src/__support/FPUtil/FEnvImpl.h (+14) 
- (modified) libc/test/UnitTest/FEnvSafeTest.cpp (+6-11) 
- (modified) libc/test/UnitTest/FPExceptMatcher.cpp (-2) 
- (modified) libc/test/UnitTest/FPMatcher.h (-2) 
- (modified) libc/test/UnitTest/RoundingModeUtils.cpp (-2) 
- (modified) libc/test/src/math/RIntTest.h (+2-5) 
- (modified) libc/test/src/math/RoundToIntegerTest.h (+2-5) 
- (modified) libc/test/src/math/smoke/CanonicalizeTest.h (+1-4) 
- (modified) libc/test/src/math/smoke/FModTest.h (-2) 
- (modified) libc/test/src/math/smoke/NearbyIntTest.h (-2) 
- (modified) libc/test/src/math/smoke/NextAfterTest.h (+1-4) 
- (modified) libc/test/src/math/smoke/NextTowardTest.h (+1-4) 
- (modified) libc/test/src/math/smoke/RIntTest.h (+2-5) 
- (modified) libc/test/src/math/smoke/RoundToIntegerTest.h (-1) 


``````````diff
diff --git a/libc/src/__support/FPUtil/FEnvImpl.h b/libc/src/__support/FPUtil/FEnvImpl.h
index 806ccb2fb1667..46572260cbc9e 100644
--- a/libc/src/__support/FPUtil/FEnvImpl.h
+++ b/libc/src/__support/FPUtil/FEnvImpl.h
@@ -71,6 +71,10 @@ LIBC_INLINE int raise_except(int excepts) {
   return feraiseexcept(excepts);
 }
 
+LIBC_INLINE int enable_except(int) { return 0; }
+
+LIBC_INLINE int disable_except(int) { return 0; }
+
 LIBC_INLINE int get_round() {
   LIBC_FENV_ACCESS_ON
   return fegetround();
@@ -81,6 +85,16 @@ LIBC_INLINE int set_round(int rounding_mode) {
   return fesetround(rounding_mode);
 }
 
+LIBC_INLINE int get_env(fenv_t *env) {
+  LIBC_FENV_ACCESS_ON
+  return fegetenv(env);
+}
+
+LIBC_INLINE int set_env(const fenv_t *env) {
+  LIBC_FENV_ACCESS_ON
+  return fesetenv(env);
+}
+
 } // namespace fputil
 } // namespace LIBC_NAMESPACE_DECL
 
diff --git a/libc/test/UnitTest/FEnvSafeTest.cpp b/libc/test/UnitTest/FEnvSafeTest.cpp
index 0747b6224cf87..6018310f4dade 100644
--- a/libc/test/UnitTest/FEnvSafeTest.cpp
+++ b/libc/test/UnitTest/FEnvSafeTest.cpp
@@ -6,10 +6,6 @@
 //
 //===---------------------------------------------------------------------===//
 
-#ifdef LIBC_MATH_USE_SYSTEM_FENV
-#undef LIBC_MATH_USE_SYSTEM_FENV
-#endif // LIBC_MATH_USE_SYSTEM_FENV
-
 #include "FEnvSafeTest.h"
 
 #include "src/__support/FPUtil/FEnvImpl.h"
@@ -45,8 +41,10 @@ void FEnvSafeTest::set_fenv(const fenv_t &fenv) {
   ASSERT_EQ(LIBC_NAMESPACE::fputil::set_env(&fenv), 0);
 }
 
-void FEnvSafeTest::expect_fenv_eq(const fenv_t &before_fenv,
-                                  const fenv_t &after_fenv) {
+void FEnvSafeTest::expect_fenv_eq([[maybe_unused]] const fenv_t &before_fenv,
+                                  [[maybe_unused]] const fenv_t &after_fenv) {
+#ifndef LIBC_MATH_USE_SYSTEM_FENV
+
 #if defined(LIBC_TARGET_ARCH_IS_AARCH64) && !defined(LIBC_COMPILER_IS_MSVC) && \
     defined(__ARM_FP)
   using FPState = LIBC_NAMESPACE::fputil::FEnv::FPState;
@@ -112,12 +110,9 @@ void FEnvSafeTest::expect_fenv_eq(const fenv_t &before_fenv,
   const uint32_t &before_fcsr = reinterpret_cast<const uint32_t &>(before_fenv);
   const uint32_t &after_fcsr = reinterpret_cast<const uint32_t &>(after_fenv);
   EXPECT_EQ(before_fcsr, after_fcsr);
+#endif // LIBC_TARGET_ARCH_*
 
-#else
-  // No arch-specific `fenv_t` support, so nothing to compare.
-  (void)before_fenv;
-  (void)after_fenv;
-#endif
+#endif // LIBC_MATH_USE_SYSTEM_FENV
 }
 
 } // namespace testing
diff --git a/libc/test/UnitTest/FPExceptMatcher.cpp b/libc/test/UnitTest/FPExceptMatcher.cpp
index d46cd7a24b80f..10b6ff9f91da1 100644
--- a/libc/test/UnitTest/FPExceptMatcher.cpp
+++ b/libc/test/UnitTest/FPExceptMatcher.cpp
@@ -11,8 +11,6 @@
 ///
 //===----------------------------------------------------------------------===//
 
-#undef LIBC_MATH_USE_SYSTEM_FENV
-
 #include "FPExceptMatcher.h"
 
 #include "src/__support/macros/config.h"
diff --git a/libc/test/UnitTest/FPMatcher.h b/libc/test/UnitTest/FPMatcher.h
index ed4a6268cd490..41188d2ad09d1 100644
--- a/libc/test/UnitTest/FPMatcher.h
+++ b/libc/test/UnitTest/FPMatcher.h
@@ -9,8 +9,6 @@
 #ifndef LLVM_LIBC_TEST_UNITTEST_FPMATCHER_H
 #define LLVM_LIBC_TEST_UNITTEST_FPMATCHER_H
 
-#undef LIBC_MATH_USE_SYSTEM_FENV
-
 #include "src/__support/CPP/array.h"
 #include "src/__support/CPP/type_traits.h"
 #include "src/__support/FPUtil/FEnvImpl.h"
diff --git a/libc/test/UnitTest/RoundingModeUtils.cpp b/libc/test/UnitTest/RoundingModeUtils.cpp
index 598b56464ec28..324d9b8a5f897 100644
--- a/libc/test/UnitTest/RoundingModeUtils.cpp
+++ b/libc/test/UnitTest/RoundingModeUtils.cpp
@@ -6,8 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#undef LIBC_MATH_USE_SYSTEM_FENV
-
 #include "RoundingModeUtils.h"
 #include "src/__support/FPUtil/FEnvImpl.h"
 #include "src/__support/FPUtil/rounding_mode.h"
diff --git a/libc/test/src/math/RIntTest.h b/libc/test/src/math/RIntTest.h
index f77f80e6b6110..990db3ea026c7 100644
--- a/libc/test/src/math/RIntTest.h
+++ b/libc/test/src/math/RIntTest.h
@@ -9,8 +9,8 @@
 #ifndef LLVM_LIBC_TEST_SRC_MATH_RINTTEST_H
 #define LLVM_LIBC_TEST_SRC_MATH_RINTTEST_H
 
-#undef LIBC_MATH_USE_SYSTEM_FENV
-
+#include "hdr/fenv_macros.h"
+#include "hdr/math_macros.h"
 #include "src/__support/CPP/algorithm.h"
 #include "src/__support/FPUtil/FPBits.h"
 #include "test/UnitTest/FEnvSafeTest.h"
@@ -18,9 +18,6 @@
 #include "test/UnitTest/Test.h"
 #include "utils/MPFRWrapper/MPFRUtils.h"
 
-#include "hdr/fenv_macros.h"
-#include "hdr/math_macros.h"
-
 namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
 using LIBC_NAMESPACE::Sign;
 
diff --git a/libc/test/src/math/RoundToIntegerTest.h b/libc/test/src/math/RoundToIntegerTest.h
index 4c71009fa91bc..27c87fb6cdd47 100644
--- a/libc/test/src/math/RoundToIntegerTest.h
+++ b/libc/test/src/math/RoundToIntegerTest.h
@@ -9,20 +9,17 @@
 #ifndef LLVM_LIBC_TEST_SRC_MATH_ROUNDTOINTEGERTEST_H
 #define LLVM_LIBC_TEST_SRC_MATH_ROUNDTOINTEGERTEST_H
 
-#include "test/UnitTest/RoundingModeUtils.h"
-#undef LIBC_MATH_USE_SYSTEM_FENV
-
+#include "hdr/math_macros.h"
 #include "src/__support/CPP/algorithm.h"
 #include "src/__support/FPUtil/FEnvImpl.h"
 #include "src/__support/FPUtil/FPBits.h"
 #include "src/__support/macros/properties/architectures.h"
 #include "test/UnitTest/FEnvSafeTest.h"
 #include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/RoundingModeUtils.h"
 #include "test/UnitTest/Test.h"
 #include "utils/MPFRWrapper/MPFRUtils.h"
 
-#include "hdr/math_macros.h"
-
 namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
 using LIBC_NAMESPACE::Sign;
 
diff --git a/libc/test/src/math/smoke/CanonicalizeTest.h b/libc/test/src/math/smoke/CanonicalizeTest.h
index 524a79acc72bd..f44827b180a6c 100644
--- a/libc/test/src/math/smoke/CanonicalizeTest.h
+++ b/libc/test/src/math/smoke/CanonicalizeTest.h
@@ -9,8 +9,7 @@
 #ifndef LLVM_LIBC_TEST_SRC_MATH_SMOKE_CANONICALIZETEST_H
 #define LLVM_LIBC_TEST_SRC_MATH_SMOKE_CANONICALIZETEST_H
 
-#undef LIBC_MATH_USE_SYSTEM_FENV
-
+#include "hdr/math_macros.h"
 #include "src/__support/FPUtil/FEnvImpl.h"
 #include "src/__support/FPUtil/FPBits.h"
 #include "src/__support/integer_literals.h"
@@ -18,8 +17,6 @@
 #include "test/UnitTest/FPMatcher.h"
 #include "test/UnitTest/Test.h"
 
-#include "hdr/math_macros.h"
-
 #define TEST_SPECIAL(x, y, expected, expected_exception)                       \
   LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);                         \
   EXPECT_EQ(expected, f(&x, &y));                                              \
diff --git a/libc/test/src/math/smoke/FModTest.h b/libc/test/src/math/smoke/FModTest.h
index cacd7a68d7cc6..ad351432dfcf5 100644
--- a/libc/test/src/math/smoke/FModTest.h
+++ b/libc/test/src/math/smoke/FModTest.h
@@ -14,8 +14,6 @@
 #ifndef LLVM_LIBC_TEST_SRC_MATH_FMODTEST_H
 #define LLVM_LIBC_TEST_SRC_MATH_FMODTEST_H
 
-#undef LIBC_MATH_USE_SYSTEM_FENV
-
 #include "hdr/errno_macros.h"
 #include "hdr/fenv_macros.h"
 #include "src/__support/FPUtil/FEnvImpl.h"
diff --git a/libc/test/src/math/smoke/NearbyIntTest.h b/libc/test/src/math/smoke/NearbyIntTest.h
index 9b6615824bdde..5d217fc2977ee 100644
--- a/libc/test/src/math/smoke/NearbyIntTest.h
+++ b/libc/test/src/math/smoke/NearbyIntTest.h
@@ -9,8 +9,6 @@
 #ifndef LLVM_LIBC_TEST_SRC_MATH_NEARBYINTTEST_H
 #define LLVM_LIBC_TEST_SRC_MATH_NEARBYINTTEST_H
 
-#undef LIBC_MATH_USE_SYSTEM_FENV
-
 #include "hdr/fenv_macros.h"
 #include "src/__support/FPUtil/FEnvImpl.h"
 #include "src/__support/FPUtil/FPBits.h"
diff --git a/libc/test/src/math/smoke/NextAfterTest.h b/libc/test/src/math/smoke/NextAfterTest.h
index 99fb7f702762b..af253d778a029 100644
--- a/libc/test/src/math/smoke/NextAfterTest.h
+++ b/libc/test/src/math/smoke/NextAfterTest.h
@@ -9,8 +9,7 @@
 #ifndef LLVM_LIBC_TEST_SRC_MATH_NEXTAFTERTEST_H
 #define LLVM_LIBC_TEST_SRC_MATH_NEXTAFTERTEST_H
 
-#undef LIBC_MATH_USE_SYSTEM_FENV
-
+#include "hdr/fenv_macros.h"
 #include "src/__support/CPP/bit.h"
 #include "src/__support/FPUtil/FEnvImpl.h"
 #include "src/__support/FPUtil/FPBits.h"
@@ -20,8 +19,6 @@
 #include "test/UnitTest/FPMatcher.h"
 #include "test/UnitTest/Test.h"
 
-#include "hdr/fenv_macros.h"
-
 using LIBC_NAMESPACE::Sign;
 
 // TODO: https://github.com/llvm/llvm-project/issues/199738
diff --git a/libc/test/src/math/smoke/NextTowardTest.h b/libc/test/src/math/smoke/NextTowardTest.h
index bf5cd243cb699..6fee0d3da86de 100644
--- a/libc/test/src/math/smoke/NextTowardTest.h
+++ b/libc/test/src/math/smoke/NextTowardTest.h
@@ -9,8 +9,7 @@
 #ifndef LLVM_LIBC_TEST_SRC_MATH_NEXTTOWARDTEST_H
 #define LLVM_LIBC_TEST_SRC_MATH_NEXTTOWARDTEST_H
 
-#undef LIBC_MATH_USE_SYSTEM_FENV
-
+#include "hdr/fenv_macros.h"
 #include "src/__support/CPP/bit.h"
 #include "src/__support/FPUtil/FEnvImpl.h"
 #include "src/__support/FPUtil/FPBits.h"
@@ -19,8 +18,6 @@
 #include "test/UnitTest/FPMatcher.h"
 #include "test/UnitTest/Test.h"
 
-#include "hdr/fenv_macros.h"
-
 using LIBC_NAMESPACE::Sign;
 
 // TODO: https://github.com/llvm/llvm-project/issues/199738
diff --git a/libc/test/src/math/smoke/RIntTest.h b/libc/test/src/math/smoke/RIntTest.h
index 82adf25b8a968..1b460050e4ae0 100644
--- a/libc/test/src/math/smoke/RIntTest.h
+++ b/libc/test/src/math/smoke/RIntTest.h
@@ -9,17 +9,14 @@
 #ifndef LLVM_LIBC_TEST_SRC_MATH_SMOKE_RINTTEST_H
 #define LLVM_LIBC_TEST_SRC_MATH_SMOKE_RINTTEST_H
 
-#undef LIBC_MATH_USE_SYSTEM_FENV
-
+#include "hdr/fenv_macros.h"
+#include "hdr/math_macros.h"
 #include "src/__support/FPUtil/FEnvImpl.h"
 #include "src/__support/FPUtil/FPBits.h"
 #include "test/UnitTest/FEnvSafeTest.h"
 #include "test/UnitTest/FPMatcher.h"
 #include "test/UnitTest/Test.h"
 
-#include "hdr/fenv_macros.h"
-#include "hdr/math_macros.h"
-
 using LIBC_NAMESPACE::Sign;
 
 template <typename T>
diff --git a/libc/test/src/math/smoke/RoundToIntegerTest.h b/libc/test/src/math/smoke/RoundToIntegerTest.h
index 16fa3879a3a6c..8cbc536e3db0f 100644
--- a/libc/test/src/math/smoke/RoundToIntegerTest.h
+++ b/libc/test/src/math/smoke/RoundToIntegerTest.h
@@ -10,7 +10,6 @@
 #define LLVM_LIBC_TEST_SRC_MATH_SMOKE_ROUNDTOINTEGERTEST_H
 
 #include "test/UnitTest/RoundingModeUtils.h"
-#undef LIBC_MATH_USE_SYSTEM_FENV
 
 #include "src/__support/CPP/algorithm.h"
 #include "src/__support/FPUtil/FEnvImpl.h"

``````````

</details>


https://github.com/llvm/llvm-project/pull/211303


More information about the libc-commits mailing list