[libc-commits] [libc] [libc][math] Avoid system fenv.h in FEnvImpl.h when LIBC_MATH_HAS_NO_EXCEPT is set (PR #224384)

Marcos Ramirez Joos via libc-commits libc-commits at lists.llvm.org
Thu Sep 17 12:02:15 PDT 2026


https://github.com/maarcosrmz updated https://github.com/llvm/llvm-project/pull/224384

>From d8d56cbf4c66bac65102154704e1365f22d1343c Mon Sep 17 00:00:00 2001
From: Marcos Ramirez Joos <mramirezjoos.oss at proton.me>
Date: Thu, 17 Sep 2026 19:34:26 +0100
Subject: [PATCH] Fix compilation (e.g. of flang) with -Wfenv-access without
 spilling internal LIBC_COMPILER_HAS_STDC_FENV_ACCESS flag

---
 libc/src/__support/FPUtil/FEnvImpl.h | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/libc/src/__support/FPUtil/FEnvImpl.h b/libc/src/__support/FPUtil/FEnvImpl.h
index 46572260cbc9e..b188511d1f6bf 100644
--- a/libc/src/__support/FPUtil/FEnvImpl.h
+++ b/libc/src/__support/FPUtil/FEnvImpl.h
@@ -31,7 +31,7 @@
 #undef LIBC_MATH_USE_SYSTEM_FENV
 #endif // LIBC_FULL_BUILD
 
-#if defined(LIBC_MATH_USE_SYSTEM_FENV)
+#if defined(LIBC_MATH_USE_SYSTEM_FENV) && !defined(LIBC_MATH_HAS_NO_EXCEPT)
 
 // Simply call the system libc fenv.h functions, only for those that are used in
 // math function implementations.
@@ -164,7 +164,6 @@ clear_except_if_required([[maybe_unused]] int excepts) {
     return 0;
   } else {
 #ifndef LIBC_MATH_HAS_NO_EXCEPT
-    LIBC_FENV_ACCESS_ON
     if (math_errhandling & MATH_ERREXCEPT)
       return clear_except(excepts);
 #endif // LIBC_MATH_HAS_NO_EXCEPT
@@ -178,7 +177,6 @@ set_except_if_required([[maybe_unused]] int excepts) {
     return 0;
   } else {
 #ifndef LIBC_MATH_HAS_NO_EXCEPT
-    LIBC_FENV_ACCESS_ON
     if (math_errhandling & MATH_ERREXCEPT)
       return set_except(excepts);
 #endif // LIBC_MATH_HAS_NO_EXCEPT
@@ -192,7 +190,6 @@ raise_except_if_required([[maybe_unused]] int excepts) {
     return 0;
   } else {
 #ifndef LIBC_MATH_HAS_NO_EXCEPT
-    LIBC_FENV_ACCESS_ON
     if (math_errhandling & MATH_ERREXCEPT)
       return raise_except(excepts);
 #endif // LIBC_MATH_HAS_NO_EXCEPT



More information about the libc-commits mailing list