Skip to content

Conversation

@philnik777
Copy link
Contributor

Always defining the macro allows us to simplify the few places where it's used.

@philnik777 philnik777 force-pushed the unconditionally_define_glibc_prereq branch from e23890a to 6228867 Compare November 24, 2025 20:57
@philnik777 philnik777 marked this pull request as ready for review November 25, 2025 11:51
@philnik777 philnik777 requested a review from a team as a code owner November 25, 2025 11:51
@philnik777 philnik777 merged commit 105900c into llvm:main Nov 25, 2025
81 checks passed
@philnik777 philnik777 deleted the unconditionally_define_glibc_prereq branch November 25, 2025 11:51
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Nov 25, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 25, 2025

@llvm/pr-subscribers-libcxx

Author: Nikolas Klauser (philnik777)

Changes

Always defining the macro allows us to simplify the few places where it's used.


Full diff: https://github.com/llvm/llvm-project/pull/169405.diff

4 Files Affected:

  • (modified) libcxx/include/__config (+6-18)
  • (modified) libcxx/include/__configuration/platform.h (+9-9)
  • (modified) libcxx/include/__random/binomial_distribution.h (+1-7)
  • (modified) libcxx/src/filesystem/operations.cpp (+2-9)
diff --git a/libcxx/include/__config b/libcxx/include/__config
index 1b27f28f9ddef..26851aad4ca92 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -678,18 +678,10 @@ typedef __char32_t char32_t;
 #    endif // _LIBCPP_HAS_THREAD_API
 #  endif   // _LIBCPP_HAS_THREADS
 
-#  if _LIBCPP_HAS_THREAD_API_PTHREAD
-#    if defined(__ANDROID__) && __ANDROID_API__ >= 30
-#      define _LIBCPP_HAS_COND_CLOCKWAIT 1
-#    elif defined(_LIBCPP_GLIBC_PREREQ)
-#      if _LIBCPP_GLIBC_PREREQ(2, 30)
-#        define _LIBCPP_HAS_COND_CLOCKWAIT 1
-#      else
-#        define _LIBCPP_HAS_COND_CLOCKWAIT 0
-#      endif
-#    else
-#      define _LIBCPP_HAS_COND_CLOCKWAIT 0
-#    endif
+#  if !_LIBCPP_HAS_THREAD_API_PTHREAD
+#    define _LIBCPP_HAS_COND_CLOCKWAIT 0
+#  elif (defined(__ANDROID__) && __ANDROID_API__ >= 30) || _LIBCPP_GLIBC_PREREQ(2, 30)
+#    define _LIBCPP_HAS_COND_CLOCKWAIT 1
 #  else
 #    define _LIBCPP_HAS_COND_CLOCKWAIT 0
 #  endif
@@ -855,12 +847,8 @@ typedef __char32_t char32_t;
 // the latter depends on internal GNU libc details that are not appropriate
 // to depend on here, so any declarations present when __cpp_char8_t is not
 // defined are ignored.
-#  if defined(_LIBCPP_GLIBC_PREREQ)
-#    if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t)
-#      define _LIBCPP_HAS_C8RTOMB_MBRTOC8 1
-#    else
-#      define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0
-#    endif
+#  if _LIBCPP_GLIBC_PREREQ(2, 36) && defined(__cpp_char8_t)
+#    define _LIBCPP_HAS_C8RTOMB_MBRTOC8 1
 #  else
 #    define _LIBCPP_HAS_C8RTOMB_MBRTOC8 0
 #  endif
diff --git a/libcxx/include/__configuration/platform.h b/libcxx/include/__configuration/platform.h
index f3c199dee172b..88bba5473c608 100644
--- a/libcxx/include/__configuration/platform.h
+++ b/libcxx/include/__configuration/platform.h
@@ -31,15 +31,15 @@
 #endif
 
 // Need to detect which libc we're using if we're on Linux.
-#if defined(__linux__) || defined(__AMDGPU__) || defined(__NVPTX__)
-#  if __has_include(<features.h>)
-#    include <features.h>
-#    if defined(__GLIBC_PREREQ)
-#      define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b)
-#    else
-#      define _LIBCPP_GLIBC_PREREQ(a, b) 0
-#    endif // defined(__GLIBC_PREREQ)
-#  endif
+#if (defined(__linux__) || defined(__AMDGPU__) || defined(__NVPTX__)) && __has_include(<features.h>)
+#  include <features.h>
+#  if defined(__GLIBC_PREREQ)
+#    define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b)
+#  else
+#    define _LIBCPP_GLIBC_PREREQ(a, b) 0
+#  endif // defined(__GLIBC_PREREQ)
+#else
+#  define _LIBCPP_GLIBC_PREREQ(a, b) 0
 #endif
 
 // This is required in order for _NEWLIB_VERSION to be defined in places where we use it.
diff --git a/libcxx/include/__random/binomial_distribution.h b/libcxx/include/__random/binomial_distribution.h
index bada8cfdd74a3..0712e4ef4a4f6 100644
--- a/libcxx/include/__random/binomial_distribution.h
+++ b/libcxx/include/__random/binomial_distribution.h
@@ -98,13 +98,7 @@ class binomial_distribution {
 };
 
 // Some libc declares the math functions to be `noexcept`.
-#if defined(_LIBCPP_GLIBC_PREREQ)
-#  if _LIBCPP_GLIBC_PREREQ(2, 8)
-#    define _LIBCPP_LGAMMA_R_NOEXCEPT _NOEXCEPT
-#  else
-#    define _LIBCPP_LGAMMA_R_NOEXCEPT
-#  endif
-#elif defined(__LLVM_LIBC__)
+#if _LIBCPP_GLIBC_PREREQ(2, 8) || defined(__LLVM_LIBC__)
 #  define _LIBCPP_LGAMMA_R_NOEXCEPT _NOEXCEPT
 #else
 #  define _LIBCPP_LGAMMA_R_NOEXCEPT
diff --git a/libcxx/src/filesystem/operations.cpp b/libcxx/src/filesystem/operations.cpp
index b71f94a89d6df..745db87ce3736 100644
--- a/libcxx/src/filesystem/operations.cpp
+++ b/libcxx/src/filesystem/operations.cpp
@@ -41,17 +41,10 @@
 #include <time.h>
 
 // since Linux 4.5 and FreeBSD 13, but the Linux libc wrapper is only provided by glibc >= 2.27 and musl
-#if defined(__linux__)
-#  if defined(_LIBCPP_GLIBC_PREREQ)
-#    if _LIBCPP_GLIBC_PREREQ(2, 27)
-#      define _LIBCPP_FILESYSTEM_USE_COPY_FILE_RANGE
-#    endif
-#  elif _LIBCPP_HAS_MUSL_LIBC
-#    define _LIBCPP_FILESYSTEM_USE_COPY_FILE_RANGE
-#  endif
-#elif defined(__FreeBSD__)
+#if _LIBCPP_GLIBC_PREREQ(2, 27) || _LIBCPP_HAS_MUSL_LIBC || defined(__FreeBSD__)
 #  define _LIBCPP_FILESYSTEM_USE_COPY_FILE_RANGE
 #endif
+
 #if __has_include(<sys/sendfile.h>)
 #  include <sys/sendfile.h>
 #  define _LIBCPP_FILESYSTEM_USE_SENDFILE

simpal01 added a commit to simpal01/arm-toolchain that referenced this pull request Nov 26, 2025
…onfig

Upstream LLVM introduced changes in libcxx/include/__config
that overlap with the area modified by our patch
0001-Define-_LIBCPP_HAS_C8RTOMB_MBRTOC8.patch. As a result,
the patch no longer applied cleanly during git am.
This PR updates and rebases the patch to reflect the
upstream modifications while preserving its original
functionality. No functional change beyond re-aligning
with upstream is intended.

Upstream change: llvm/llvm-project#169405
simpal01 added a commit to arm/arm-toolchain that referenced this pull request Nov 26, 2025
…onfig (#625)

Upstream LLVM introduced changes in libcxx/include/__config that overlap
with the area modified by our patch
0001-Define-_LIBCPP_HAS_C8RTOMB_MBRTOC8.patch. As a result, the patch no
longer applied cleanly during git am. This PR updates and rebases the
patch to reflect the upstream modifications while preserving its
original functionality. No functional change beyond re-aligning with
upstream is intended.

Upstream change: llvm/llvm-project#169405
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants