[flang-commits] [flang] [flang] Fix POSIX.1/XPG checks in intrinsics-library.cpp (PR #201072)
via flang-commits
flang-commits at lists.llvm.org
Tue Jun 2 02:16:54 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Rainer Orth (rorth)
<details>
<summary>Changes</summary>
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`.
---
Full diff: https://github.com/llvm/llvm-project/pull/201072.diff
1 Files Affected:
- (modified) flang/lib/Evaluate/intrinsics-library.cpp (+2-2)
``````````diff
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> {
``````````
</details>
https://github.com/llvm/llvm-project/pull/201072
More information about the flang-commits
mailing list