[libcxx-commits] [libcxx] [libc++] Always define _LIBCPP_GLIBC_PREREQ (PR #169405)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Nov 24 12:50:23 PST 2025
https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/169405
Always defining the macro allows us to simplify the few places where it's used.
>From e23890a1378b8b92ed0049cf98a52397ea5bab8e Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Mon, 24 Nov 2025 21:49:23 +0100
Subject: [PATCH] [libc++] Always define _LIBCPP_GLIBC_PREREQ
---
libcxx/include/__config | 24 +++++--------------
libcxx/include/__configuration/platform.h | 18 +++++++-------
.../include/__random/binomial_distribution.h | 8 +------
libcxx/src/filesystem/operations.cpp | 13 ++++------
4 files changed, 21 insertions(+), 42 deletions(-)
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..4f0cbb956fc0b 100644
--- a/libcxx/src/filesystem/operations.cpp
+++ b/libcxx/src/filesystem/operations.cpp
@@ -41,17 +41,14 @@
#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
+#if _LIBCPP_GLIBC_PREREQ(2, 27)
+# define _LIBCPP_FILESYSTEM_USE_COPY_FILE_RANGE
+#elif _LIBCPP_HAS_MUSL_LIBC
+# define _LIBCPP_FILESYSTEM_USE_COPY_FILE_RANGE
#elif 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
More information about the libcxx-commits
mailing list