From 1e0457b899e7d12ee80b53343fcc5964b7eb6669 Mon Sep 17 00:00:00 2001 From: Ryan Prichard Date: Tue, 3 Jun 2025 17:18:53 -0700 Subject: [PATCH 1/2] [libc++][Android] Always redirect to When targeting Android, enable the to redirection for C++ language dialects before C++23, because this redirection historically existed for Android's C++ toolchain. Currently, the Android toolchain achieves this redirection with a stdatomic.h in the sysroot (from Bionic) that defines the C API either directly or by aliasing std identifiers from . The Android team's LLVM build scripts then copy Bionic's header over the one in the Clang resource directory. Hopefully, by moving Android's redirection into LLVM itself, the Android stdatomic.h situation can be simplified eventually. --- libcxx/include/atomic | 5 ++++- libcxx/include/stdatomic.h | 5 ++++- .../atomics.syn/compatible_with_stdatomic.compile.pass.cpp | 5 ++++- .../atomics.syn/incompatible_with_stdatomic.verify.cpp | 3 +++ .../dont_hijack_header.cxx23.compile.pass.cpp | 3 +++ 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/libcxx/include/atomic b/libcxx/include/atomic index 75af5de33ca4c..fba7040f6900c 100644 --- a/libcxx/include/atomic +++ b/libcxx/include/atomic @@ -598,7 +598,10 @@ template # define _LIBCPP_STDATOMIC_H_HAS_DEFINITELY_BEEN_INCLUDED 0 # endif -# if _LIBCPP_STD_VER < 23 && _LIBCPP_STDATOMIC_H_HAS_DEFINITELY_BEEN_INCLUDED +// The Android LLVM toolchain has historically allowed combining the +// and headers in dialects before C++23, so for backwards +// compatibility, preserve that ability when targeting Android. +# if _LIBCPP_STD_VER < 23 && !defined(__ANDROID__) && _LIBCPP_STDATOMIC_H_HAS_DEFINITELY_BEEN_INCLUDED # error is incompatible with before C++23. Please compile with -std=c++23. # endif diff --git a/libcxx/include/stdatomic.h b/libcxx/include/stdatomic.h index 2991030eee456..dc1a955b69cb6 100644 --- a/libcxx/include/stdatomic.h +++ b/libcxx/include/stdatomic.h @@ -126,7 +126,10 @@ using std::atomic_signal_fence // see below # pragma GCC system_header # endif -# if defined(__cplusplus) && _LIBCPP_STD_VER >= 23 +// The Android LLVM toolchain has historically allowed combining the +// and headers in dialects before C++23, so for backwards +// compatibility, preserve that ability when targeting Android. +# if defined(__cplusplus) && (_LIBCPP_STD_VER >= 23 || defined(__ANDROID__)) # include # include diff --git a/libcxx/test/libcxx/atomics/atomics.syn/compatible_with_stdatomic.compile.pass.cpp b/libcxx/test/libcxx/atomics/atomics.syn/compatible_with_stdatomic.compile.pass.cpp index 349dc51aaa0e6..c997e4b792459 100644 --- a/libcxx/test/libcxx/atomics/atomics.syn/compatible_with_stdatomic.compile.pass.cpp +++ b/libcxx/test/libcxx/atomics/atomics.syn/compatible_with_stdatomic.compile.pass.cpp @@ -7,7 +7,10 @@ //===----------------------------------------------------------------------===// // UNSUPPORTED: no-threads -// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 + +// On Android, libc++'s header always redirects to , even before C++23. +// UNSUPPORTED: c++03 +// UNSUPPORTED: (c++11 || c++14 || c++17 || c++20) && !android // This test verifies that redirects to . diff --git a/libcxx/test/libcxx/atomics/atomics.syn/incompatible_with_stdatomic.verify.cpp b/libcxx/test/libcxx/atomics/atomics.syn/incompatible_with_stdatomic.verify.cpp index a788ea32dddc8..7d14fa308bf06 100644 --- a/libcxx/test/libcxx/atomics/atomics.syn/incompatible_with_stdatomic.verify.cpp +++ b/libcxx/test/libcxx/atomics/atomics.syn/incompatible_with_stdatomic.verify.cpp @@ -9,6 +9,9 @@ // UNSUPPORTED: no-threads // REQUIRES: c++03 || c++11 || c++14 || c++17 || c++20 +// On Android, libc++'s header always redirects to , even before C++23. +// XFAIL: android + // No diagnostic gets emitted when we build with modules. // XFAIL: clang-modules-build diff --git a/libcxx/test/libcxx/atomics/stdatomic.h.syn/dont_hijack_header.cxx23.compile.pass.cpp b/libcxx/test/libcxx/atomics/stdatomic.h.syn/dont_hijack_header.cxx23.compile.pass.cpp index a8a99e6937f31..5c966c6bca6e2 100644 --- a/libcxx/test/libcxx/atomics/stdatomic.h.syn/dont_hijack_header.cxx23.compile.pass.cpp +++ b/libcxx/test/libcxx/atomics/stdatomic.h.syn/dont_hijack_header.cxx23.compile.pass.cpp @@ -21,6 +21,9 @@ // doesn't work at all if we don't use the provided by libc++ in C++23 and above. // XFAIL: (c++11 || c++14 || c++17 || c++20) && gcc +// On Android, libc++'s header always redirects to , even before C++23. +// XFAIL: android + #include #include #include From 44a582484585e11964b1ebde198d1071ade86676 Mon Sep 17 00:00:00 2001 From: Ryan Prichard Date: Tue, 24 Jun 2025 16:02:35 -0700 Subject: [PATCH 2/2] Move c++03 onto the same line as the other dialects For Android, when/if we test C++03, we will verify that stdatomic.h and atomic can be included simultaneously. --- .../atomics.syn/compatible_with_stdatomic.compile.pass.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libcxx/test/libcxx/atomics/atomics.syn/compatible_with_stdatomic.compile.pass.cpp b/libcxx/test/libcxx/atomics/atomics.syn/compatible_with_stdatomic.compile.pass.cpp index c997e4b792459..a8462a4668220 100644 --- a/libcxx/test/libcxx/atomics/atomics.syn/compatible_with_stdatomic.compile.pass.cpp +++ b/libcxx/test/libcxx/atomics/atomics.syn/compatible_with_stdatomic.compile.pass.cpp @@ -9,8 +9,7 @@ // UNSUPPORTED: no-threads // On Android, libc++'s header always redirects to , even before C++23. -// UNSUPPORTED: c++03 -// UNSUPPORTED: (c++11 || c++14 || c++17 || c++20) && !android +// UNSUPPORTED: (c++03 || c++11 || c++14 || c++17 || c++20) && !android // This test verifies that redirects to .