[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:01:15 PDT 2026
https://github.com/maarcosrmz created https://github.com/llvm/llvm-project/pull/224384
The warning being added under #199009 triggers errors in subprojects (e.g., flang) using libc headers that gate the use of `#pragma STDC FENV_ACCESS ON` on the internal libc `LIBC_COMPILER_HAS_STDC_FENV_ACCESS` flag, when building under `-Wfenv-access -Werror`. As the idea is for these subprojects to not access the libc FP environment (see https://github.com/llvm/llvm-project/pull/199009#issuecomment-5299119396), gating the use of system fenv.h functions on the `LIBC_MATH_HAS_NO_EXCEPT` flag avoids having to specify the `LIBC_COMPILER_HAS_STDC_FENV_ACCESS` flag when building them.
>From 0badd1955050ceaf0bec8b37b77a8ee56ea26019 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..9adb426634462 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) && not 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