[libc++] Provide flag for RUNTIMES_USE_LIBC=llvm-libc#174967
[libc++] Provide flag for RUNTIMES_USE_LIBC=llvm-libc#174967
Conversation
There was no flag added for llvm-libc when picolibc and newlib were provided in llvm#147956 - the missing flag breaks libc++ iostream support now because this check https://github.com/llvm/llvm-project/blob/9a8421fa6191d2e1047e3dc8c72a22fa810f9aee/libcxx/include/__config#L719 fails unless an LLVM libc header is included.
|
@llvm/pr-subscribers-libcxx Author: Volodymyr Turanskyy (voltur01) ChangesThere was no flag added for llvm-libc when picolibc and newlib were provided in #147956 - the missing flag breaks libc++ iostream support now because this check llvm-project/libcxx/include/__config Line 719 in 9a8421f Full diff: https://github.com/llvm/llvm-project/pull/174967.diff 7 Files Affected:
diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 8b4cd2636fd4d..9f75f65d54af2 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -773,6 +773,8 @@ if (RUNTIMES_USE_LIBC STREQUAL "picolibc")
config_define(1 _LIBCPP_LIBC_NEWLIB)
elseif (RUNTIMES_USE_LIBC STREQUAL "newlib")
config_define(1 _LIBCPP_LIBC_NEWLIB)
+elseif (RUNTIMES_USE_LIBC STREQUAL "llvm-libc")
+ config_define(1 _LIBCPP_LIBC_LLVM_LIBC)
endif()
# TODO: Remove in LLVM 21. We're leaving an error to make this fail explicitly.
diff --git a/libcxx/include/__config b/libcxx/include/__config
index b4db39472ce31..2cadce967d689 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -716,7 +716,7 @@ typedef __char32_t char32_t;
# endif
# if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \
- _LIBCPP_HAS_MUSL_LIBC || defined(__OpenBSD__) || defined(__LLVM_LIBC__)
+ _LIBCPP_HAS_MUSL_LIBC || defined(__OpenBSD__) || _LIBCPP_LIBC_LLVM_LIBC
# define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
# endif
diff --git a/libcxx/include/__config_site.in b/libcxx/include/__config_site.in
index b09ca807ee812..a1cc1208aeff3 100644
--- a/libcxx/include/__config_site.in
+++ b/libcxx/include/__config_site.in
@@ -45,6 +45,7 @@
// C libraries
#cmakedefine01 _LIBCPP_LIBC_PICOLIBC
#cmakedefine01 _LIBCPP_LIBC_NEWLIB
+#cmakedefine01 _LIBCPP_LIBC_LLVM_LIBC
// __USE_MINGW_ANSI_STDIO gets redefined on MinGW
#ifdef __clang__
diff --git a/libcxx/include/__random/binomial_distribution.h b/libcxx/include/__random/binomial_distribution.h
index 0712e4ef4a4f6..6d07ff3c7df04 100644
--- a/libcxx/include/__random/binomial_distribution.h
+++ b/libcxx/include/__random/binomial_distribution.h
@@ -98,7 +98,7 @@ class binomial_distribution {
};
// Some libc declares the math functions to be `noexcept`.
-#if _LIBCPP_GLIBC_PREREQ(2, 8) || defined(__LLVM_LIBC__)
+#if _LIBCPP_GLIBC_PREREQ(2, 8) || _LIBCPP_LIBC_LLVM_LIBC
# define _LIBCPP_LGAMMA_R_NOEXCEPT _NOEXCEPT
#else
# define _LIBCPP_LGAMMA_R_NOEXCEPT
diff --git a/libcxx/src/chrono.cpp b/libcxx/src/chrono.cpp
index 20387ea76124b..a27efc5a42b5d 100644
--- a/libcxx/src/chrono.cpp
+++ b/libcxx/src/chrono.cpp
@@ -31,7 +31,7 @@
# include <sys/time.h> // for gettimeofday and timeval
#endif
-#if defined(__LLVM_LIBC__)
+#if _LIBCPP_LIBC_LLVM_LIBC
# define _LIBCPP_HAS_TIMESPEC_GET
#endif
diff --git a/libcxx/src/filesystem/filesystem_clock.cpp b/libcxx/src/filesystem/filesystem_clock.cpp
index 49f65efb5a53a..865a1018871f2 100644
--- a/libcxx/src/filesystem/filesystem_clock.cpp
+++ b/libcxx/src/filesystem/filesystem_clock.cpp
@@ -32,7 +32,7 @@
# include <sys/time.h> // for gettimeofday and timeval
#endif
-#if defined(__LLVM_LIBC__)
+#if _LIBCPP_LIBC_LLVM_LIBC
# define _LIBCPP_HAS_TIMESPEC_GET
#endif
diff --git a/libcxx/src/include/config_elast.h b/libcxx/src/include/config_elast.h
index be665a97bf91b..daec2429de8eb 100644
--- a/libcxx/src/include/config_elast.h
+++ b/libcxx/src/include/config_elast.h
@@ -21,7 +21,7 @@
// where strerror/strerror_r can't handle out-of-range errno values.
#if defined(ELAST)
# define _LIBCPP_ELAST ELAST
-#elif defined(__LLVM_LIBC__)
+#elif _LIBCPP_LIBC_LLVM_LIBC
// No _LIBCPP_ELAST needed for LLVM libc
#elif _LIBCPP_LIBC_NEWLIB
# define _LIBCPP_ELAST __ELASTERROR
|
|
I made this change consistent with other C library flags (picolibc and newlib), however I can imagine that the @petrhosek do you have more context in regards to existing checks for libc in libc++? Alternative would be to define Thanks! |
saturn691
left a comment
There was a problem hiding this comment.
LGTM, but I think someone from llvm/reviewers-libcxx should also have a look
| #if _LIBCPP_LIBC_LLVM_LIBC | ||
| # define _LIBCPP_HAS_TIMESPEC_GET | ||
| #endif |
There was a problem hiding this comment.
| #if _LIBCPP_LIBC_LLVM_LIBC | |
| # define _LIBCPP_HAS_TIMESPEC_GET | |
| #endif | |
| #define _LIBCPP_HAS_TIMESPEC_GET _LIBCPP_LIBC_LLVM_LIBC |
Same below.
There was a problem hiding this comment.
Thank you for the review and suggestion!
Just to confirm, _LIBCPP_LIBC_LLVM_LIBC will be always defined and set to either 0 or 1 depending on the C library in use. So current logic will define the other flag _LIBCPP_HAS_TIMESPEC_GET only if _LIBCPP_LIBC_LLVM_LIBC == 1.
However, in the suggested simplified definition of _LIBCPP_HAS_TIMESPEC_GET it will be always defined even if _LIBCPP_LIBC_LLVM_LIBC == 0 - taking into account that below in the file
_LIBCPP_HAS_TIMESPEC_GET is defined or not (regardless of its value) setting it to 0 when _LIBCPP_LIBC_LLVM_LIBC == 0 will change the behavior of the code. So the simplified definition is not equivalent to the current behavior, which, I believe, is undesired.
There was a problem hiding this comment.
Oh, I didn't realize that. It should always be defined and checked for #if _LIBCPP_HAS_TIMESPEC_GET instead, but that should be fixed in a separate PR. Feel free to ignore.
There was a problem hiding this comment.
Thank you for the confirmation!
|
Merging on behalf of @voltur01 as he doesn't have merging privileges. |
After llvm/llvm-project#174967 RUNTIMES_USE_LIBC=llvm-libc option provides all necessary defines for libcxx to work with LLVM libc.
After llvm/llvm-project#174967 RUNTIMES_USE_LIBC=llvm-libc option provides all necessary defines for libcxx to work with LLVM libc.
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/72/builds/16967 Here is the relevant piece of the build log for the reference |
There was no flag added for llvm-libc when picolibc and newlib were provided in llvm#147956 - the missing flag breaks libc++ iostream support now because this check https://github.com/llvm/llvm-project/blob/9a8421fa6191d2e1047e3dc8c72a22fa810f9aee/libcxx/include/__config#L719 fails unless an LLVM libc header is included.
After llvm/llvm-project#174967 RUNTIMES_USE_LIBC=llvm-libc option provides all necessary defines for libcxx to work with LLVM libc.
After llvm/llvm-project#174967 RUNTIMES_USE_LIBC=llvm-libc option provides all necessary defines for libcxx to work with LLVM libc. (cherry picked from commit 227f790)
There was no flag added for llvm-libc when picolibc and newlib were provided in llvm#147956 - the missing flag breaks libc++ iostream support now because this check https://github.com/llvm/llvm-project/blob/9a8421fa6191d2e1047e3dc8c72a22fa810f9aee/libcxx/include/__config#L719 fails unless an LLVM libc header is included.
There was no flag added for llvm-libc when picolibc and newlib were provided in #147956 - the missing flag breaks libc++ iostream support now because this check
llvm-project/libcxx/include/__config
Line 719 in 9a8421f