[flang-commits] [flang] [flang] Fix POSIX.1/XPG checks in intrinsics-library.cpp (PR #201072)

Rainer Orth via flang-commits flang-commits at lists.llvm.org
Tue Jun 2 07:20:26 PDT 2026


https://github.com/rorth updated https://github.com/llvm/llvm-project/pull/201072

>From 1aad7dff1935e35b4a1145715600c05cc1e768d2 Mon Sep 17 00:00:00 2001
From: Rainer Orth <ro at gcc.gnu.org>
Date: Tue, 2 Jun 2026 11:07:31 +0200
Subject: [PATCH 1/2] [flang] Fix POSIX.1/XPG checks in intrinsics-library.cpp

PR #201063 breaks the `flang` build on Solaris:

```
flang/lib/Evaluate/intrinsics-library.cpp:225:26: error: address of overloaded function 'acos' does not match required type '__float128 (__float128)'
flang/lib/Evaluate/intrinsics-library.cpp:225:26: error: address of overloaded function 'acos' does not match required type '_Complex __float128 (_Complex __float128)'

```

The problem is that the `__float128` support in `intrinsics-library.cpp` is
guarded incorrectly: it tests for `_POSIX_C_SOURCE >= 200112L` or
`_XOPEN_SOURCE >= 600`, which are no longer defined on Solaris after the PR
above.  This check is due a misunderstanding of those feature test macros:
as detailed in [The Open Group Base Specifications Issue 8, 2.2.1 POSIX.1
Symbols](https://pubs.opengroup.org/onlinepubs/9799919799/functions/V2_chap02.html),
those macros are expected to be **defined** by the user to ensure that the
features introduced by a particular version of POSIX.1 or XPG are enabled.
To test if they actually are supported, the values of `_POSIX_VERSION` or
`_XOPEN_VERSION` need to be checked instead, as explained in [2.1.3.1 POSIX
System
Interfaces](https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap02.html).

If the XPG6 features required for `flang` are present by default in a
compilation environment, `_POSIX_VERSION` or `_XOPEN_VERSION` will be
defined to the required values even without defining `_POSIX_C_SOURCE` or
`_XOPEN_SOURCE`.

Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and
`x86_64-pc-linux-gnu`.
---
 flang/lib/Evaluate/intrinsics-library.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/flang/lib/Evaluate/intrinsics-library.cpp b/flang/lib/Evaluate/intrinsics-library.cpp
index 54726ac539d60..68d47d2c248b3 100644
--- a/flang/lib/Evaluate/intrinsics-library.cpp
+++ b/flang/lib/Evaluate/intrinsics-library.cpp
@@ -440,7 +440,7 @@ struct HostRuntimeLibrary<std::complex<double>, LibraryVersion::Libm> {
 //    clang libc++ (ok in GNU libstdc++). Instead, the Posix libm
 //    extensions are used when available below.
 
-#if _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600
+#if _POSIX_VERSION >= 200112L || _XOPEN_VERSION >= 600
 /// Define libm extensions
 /// Bessel functions are defined in POSIX.1-2001.
 
@@ -557,7 +557,7 @@ struct HostRuntimeLibrary<long double, LibraryVersion::LibmExtensions> {
   static_assert(map.Verify(), "map must be sorted");
 };
 #endif // HAS_FLOAT80 || HAS_LDBL128
-#endif //_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600
+#endif //_POSIX_VERSION >= 200112L || _XOPEN_VERSION >= 600
 
 #ifdef _WIN32
 template <> struct HostRuntimeLibrary<double, LibraryVersion::LibmExtensions> {

>From 58fa09033d2cc3335f3448969ad28f62258e6e90 Mon Sep 17 00:00:00 2001
From: Rainer Orth <ro at gcc.gnu.org>
Date: Tue, 2 Jun 2026 16:19:30 +0200
Subject: [PATCH 2/2] Check both `_POSIX_C_SOURCE` and `_POSIX_VERSION`,
 `_XOPEN_SOURCE` and `_XOPEN_VERSION`.

---
 flang/lib/Evaluate/intrinsics-library.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/flang/lib/Evaluate/intrinsics-library.cpp b/flang/lib/Evaluate/intrinsics-library.cpp
index 68d47d2c248b3..f1eb60f343d9a 100644
--- a/flang/lib/Evaluate/intrinsics-library.cpp
+++ b/flang/lib/Evaluate/intrinsics-library.cpp
@@ -440,7 +440,8 @@ struct HostRuntimeLibrary<std::complex<double>, LibraryVersion::Libm> {
 //    clang libc++ (ok in GNU libstdc++). Instead, the Posix libm
 //    extensions are used when available below.
 
-#if _POSIX_VERSION >= 200112L || _XOPEN_VERSION >= 600
+#if _POSIX_C_SOURCE >= 200112L || _POSIX_VERSION >= 200112L || \
+    _XOPEN_SOURCE >= 600 || _XOPEN_VERSION >= 600
 /// Define libm extensions
 /// Bessel functions are defined in POSIX.1-2001.
 
@@ -557,7 +558,8 @@ struct HostRuntimeLibrary<long double, LibraryVersion::LibmExtensions> {
   static_assert(map.Verify(), "map must be sorted");
 };
 #endif // HAS_FLOAT80 || HAS_LDBL128
-#endif //_POSIX_VERSION >= 200112L || _XOPEN_VERSION >= 600
+#endif //_POSIX_C_SOURCE >= 200112L || _POSIX_VERSION >= 200112L ||
+       //_XOPEN_VERSION >= 600 || _XOPEN_VERSION >= 600
 
 #ifdef _WIN32
 template <> struct HostRuntimeLibrary<double, LibraryVersion::LibmExtensions> {



More information about the flang-commits mailing list