Skip to content

Commit 1e0457b

Browse files
committed
[libc++][Android] Always redirect <stdatomic.h> to <atomic>
When targeting Android, enable the <stdatomic.h> to <atomic> 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 <atomic>. 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.
1 parent 857138b commit 1e0457b

File tree

5 files changed

+18
-3
lines changed

5 files changed

+18
-3
lines changed

libcxx/include/atomic

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,10 @@ template <class T>
598598
# define _LIBCPP_STDATOMIC_H_HAS_DEFINITELY_BEEN_INCLUDED 0
599599
# endif
600600

601-
# if _LIBCPP_STD_VER < 23 && _LIBCPP_STDATOMIC_H_HAS_DEFINITELY_BEEN_INCLUDED
601+
// The Android LLVM toolchain has historically allowed combining the <atomic>
602+
// and <stdatomic.h> headers in dialects before C++23, so for backwards
603+
// compatibility, preserve that ability when targeting Android.
604+
# if _LIBCPP_STD_VER < 23 && !defined(__ANDROID__) && _LIBCPP_STDATOMIC_H_HAS_DEFINITELY_BEEN_INCLUDED
602605
# error <atomic> is incompatible with <stdatomic.h> before C++23. Please compile with -std=c++23.
603606
# endif
604607

libcxx/include/stdatomic.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ using std::atomic_signal_fence // see below
126126
# pragma GCC system_header
127127
# endif
128128

129-
# if defined(__cplusplus) && _LIBCPP_STD_VER >= 23
129+
// The Android LLVM toolchain has historically allowed combining the <atomic>
130+
// and <stdatomic.h> headers in dialects before C++23, so for backwards
131+
// compatibility, preserve that ability when targeting Android.
132+
# if defined(__cplusplus) && (_LIBCPP_STD_VER >= 23 || defined(__ANDROID__))
130133

131134
# include <atomic>
132135
# include <version>

libcxx/test/libcxx/atomics/atomics.syn/compatible_with_stdatomic.compile.pass.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
//===----------------------------------------------------------------------===//
88

99
// UNSUPPORTED: no-threads
10-
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10+
11+
// On Android, libc++'s <stdatomic.h> header always redirects to <atomic>, even before C++23.
12+
// UNSUPPORTED: c++03
13+
// UNSUPPORTED: (c++11 || c++14 || c++17 || c++20) && !android
1114

1215
// This test verifies that <stdatomic.h> redirects to <atomic>.
1316

libcxx/test/libcxx/atomics/atomics.syn/incompatible_with_stdatomic.verify.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
// UNSUPPORTED: no-threads
1010
// REQUIRES: c++03 || c++11 || c++14 || c++17 || c++20
1111

12+
// On Android, libc++'s <stdatomic.h> header always redirects to <atomic>, even before C++23.
13+
// XFAIL: android
14+
1215
// No diagnostic gets emitted when we build with modules.
1316
// XFAIL: clang-modules-build
1417

libcxx/test/libcxx/atomics/stdatomic.h.syn/dont_hijack_header.cxx23.compile.pass.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
// doesn't work at all if we don't use the <stdatomic.h> provided by libc++ in C++23 and above.
2222
// XFAIL: (c++11 || c++14 || c++17 || c++20) && gcc
2323

24+
// On Android, libc++'s <stdatomic.h> header always redirects to <atomic>, even before C++23.
25+
// XFAIL: android
26+
2427
#include <atomic>
2528
#include <stdatomic.h>
2629
#include <type_traits>

0 commit comments

Comments
 (0)