From 1aad7dff1935e35b4a1145715600c05cc1e768d2 Mon Sep 17 00:00:00 2001 From: Rainer Orth Date: Tue, 2 Jun 2026 11:07:31 +0200 Subject: [PATCH 1/4] [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, 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 { 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 { From 58fa09033d2cc3335f3448969ad28f62258e6e90 Mon Sep 17 00:00:00 2001 From: Rainer Orth Date: Tue, 2 Jun 2026 16:19:30 +0200 Subject: [PATCH 2/4] 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, 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 { 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 { From 56a8100c48206e6aebf1111a459c7bd1604d5c81 Mon Sep 17 00:00:00 2001 From: Rainer Orth Date: Thu, 30 Jul 2026 09:30:55 +0200 Subject: [PATCH 3/4] Fix POSIX.1/XPG check. Move quadmathlib code out of POSIX.1/XPG guard. --- flang/lib/Evaluate/intrinsics-library.cpp | 111 +++++++++++----------- 1 file changed, 55 insertions(+), 56 deletions(-) diff --git a/flang/lib/Evaluate/intrinsics-library.cpp b/flang/lib/Evaluate/intrinsics-library.cpp index f1eb60f343d9a..7ef71107879dd 100644 --- a/flang/lib/Evaluate/intrinsics-library.cpp +++ b/flang/lib/Evaluate/intrinsics-library.cpp @@ -28,6 +28,7 @@ #include "flang/Common/float128.h" #include "flang/Common/float80.h" #include +#include namespace Fortran::evaluate { @@ -440,8 +441,7 @@ struct HostRuntimeLibrary, LibraryVersion::Libm> { // clang libc++ (ok in GNU libstdc++). Instead, the Posix libm // extensions are used when available below. -#if _POSIX_C_SOURCE >= 200112L || _POSIX_VERSION >= 200112L || \ - _XOPEN_SOURCE >= 600 || _XOPEN_VERSION >= 600 +#if _POSIX_VERSION >= 200112L || _XOPEN_VERSION >= 600 /// Define libm extensions /// Bessel functions are defined in POSIX.1-2001. @@ -461,7 +461,58 @@ template <> struct HostRuntimeLibrary { static constexpr HostRuntimeMap map{table}; static_assert(map.Verify(), "map must be sorted"); }; -#endif +#endif // !_AIX && !__APPLE__ + +template <> struct HostRuntimeLibrary { + using F = FuncPointer; + using FN = FuncPointer; + static constexpr HostRuntimeFunction table[]{ + FolderFactory::Create("bessel_j0"), + FolderFactory::Create("bessel_j1"), + FolderFactory::Create("bessel_jn"), + FolderFactory::Create("bessel_y0"), + FolderFactory::Create("bessel_y1"), + FolderFactory::Create("bessel_yn"), + }; + static constexpr HostRuntimeMap map{table}; + static_assert(map.Verify(), "map must be sorted"); +}; + +#if defined(__GLIBC__) && (HAS_FLOAT80 || HAS_LDBL128) +template <> +struct HostRuntimeLibrary { + using F = FuncPointer; + using FN = FuncPointer; + static constexpr HostRuntimeFunction table[]{ + FolderFactory::Create("bessel_j0"), + FolderFactory::Create("bessel_j1"), + FolderFactory::Create("bessel_jn"), + FolderFactory::Create("bessel_y0"), + FolderFactory::Create("bessel_y1"), + FolderFactory::Create("bessel_yn"), + }; + static constexpr HostRuntimeMap map{table}; + static_assert(map.Verify(), "map must be sorted"); +}; +#endif // __GLIBC__ && (HAS_FLOAT80 || HAS_LDBL128) +#endif // _POSIX_VERSION >= 200112L || _XOPEN_VERSION >= 600 + +#ifdef _WIN32 +template <> struct HostRuntimeLibrary { + using F = FuncPointer; + using FN = FuncPointer; + static constexpr HostRuntimeFunction table[]{ + FolderFactory::Create("bessel_j0"), + FolderFactory::Create("bessel_j1"), + FolderFactory::Create("bessel_jn"), + FolderFactory::Create("bessel_y0"), + FolderFactory::Create("bessel_y1"), + FolderFactory::Create("bessel_yn"), + }; + static constexpr HostRuntimeMap map{table}; + static_assert(map.Verify(), "map must be sorted"); +}; +#endif // _WIN32 #if HAS_QUADMATHLIB template <> struct HostRuntimeLibrary<__float128, LibraryVersion::Libm> { @@ -524,59 +575,7 @@ template <> struct HostRuntimeLibrary<__complex128, LibraryVersion::Libm> { static constexpr HostRuntimeMap map{table}; static_assert(map.Verify(), "map must be sorted"); }; -#endif - -template <> struct HostRuntimeLibrary { - using F = FuncPointer; - using FN = FuncPointer; - static constexpr HostRuntimeFunction table[]{ - FolderFactory::Create("bessel_j0"), - FolderFactory::Create("bessel_j1"), - FolderFactory::Create("bessel_jn"), - FolderFactory::Create("bessel_y0"), - FolderFactory::Create("bessel_y1"), - FolderFactory::Create("bessel_yn"), - }; - static constexpr HostRuntimeMap map{table}; - static_assert(map.Verify(), "map must be sorted"); -}; - -#if defined(__GLIBC__) && (HAS_FLOAT80 || HAS_LDBL128) -template <> -struct HostRuntimeLibrary { - using F = FuncPointer; - using FN = FuncPointer; - static constexpr HostRuntimeFunction table[]{ - FolderFactory::Create("bessel_j0"), - FolderFactory::Create("bessel_j1"), - FolderFactory::Create("bessel_jn"), - FolderFactory::Create("bessel_y0"), - FolderFactory::Create("bessel_y1"), - FolderFactory::Create("bessel_yn"), - }; - static constexpr HostRuntimeMap map{table}; - static_assert(map.Verify(), "map must be sorted"); -}; -#endif // HAS_FLOAT80 || HAS_LDBL128 -#endif //_POSIX_C_SOURCE >= 200112L || _POSIX_VERSION >= 200112L || - //_XOPEN_VERSION >= 600 || _XOPEN_VERSION >= 600 - -#ifdef _WIN32 -template <> struct HostRuntimeLibrary { - using F = FuncPointer; - using FN = FuncPointer; - static constexpr HostRuntimeFunction table[]{ - FolderFactory::Create("bessel_j0"), - FolderFactory::Create("bessel_j1"), - FolderFactory::Create("bessel_jn"), - FolderFactory::Create("bessel_y0"), - FolderFactory::Create("bessel_y1"), - FolderFactory::Create("bessel_yn"), - }; - static constexpr HostRuntimeMap map{table}; - static_assert(map.Verify(), "map must be sorted"); -}; -#endif +#endif // HAS_QUADMATHLIB /// Define pgmath description #if LINK_WITH_LIBPGMATH From 94859925968cfa64dbbe96d1d03af4fd65e3e5c3 Mon Sep 17 00:00:00 2001 From: Rainer Orth Date: Thu, 30 Jul 2026 10:26:45 +0200 Subject: [PATCH 4/4] Don't include on Windows. --- flang/lib/Evaluate/intrinsics-library.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/flang/lib/Evaluate/intrinsics-library.cpp b/flang/lib/Evaluate/intrinsics-library.cpp index 7ef71107879dd..5d16d5e436fbc 100644 --- a/flang/lib/Evaluate/intrinsics-library.cpp +++ b/flang/lib/Evaluate/intrinsics-library.cpp @@ -28,7 +28,9 @@ #include "flang/Common/float128.h" #include "flang/Common/float80.h" #include -#include +#ifndef _WIN32 +#include // _POSIX_VERSION, _XOPEN_VERSION +#endif namespace Fortran::evaluate {