Skip to content

[libc++][Android] Always redirect <stdatomic.h> to <atomic> #143036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion libcxx/include/atomic
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,10 @@ template <class T>
# 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 <atomic>
// and <stdatomic.h> 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 <atomic> is incompatible with <stdatomic.h> before C++23. Please compile with -std=c++23.
# endif

Expand Down
5 changes: 4 additions & 1 deletion libcxx/include/stdatomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <atomic>
// and <stdatomic.h> 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 <atomic>
# include <version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
//===----------------------------------------------------------------------===//

// UNSUPPORTED: no-threads
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20

// On Android, libc++'s <stdatomic.h> header always redirects to <atomic>, even before C++23.
// UNSUPPORTED: c++03
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is c++03 on a separate line now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It probably shouldn't be on a separate line -- it looks like libc++ does support <atomic> for C++03.

Though now I'm wondering if the UNSUPPORTED directive ought to be XFAIL instead. I think the libc++ project usually prefers XFAIL when we know that a test should fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose UNSUPPORTED might be fine, though, because for previous language dialects, we have the incompatible_with_stdatomic.verify.cpp test already.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd move back c++03 on the same line as the other ones. I'm neutral on XFAIL vs UNSUPPORTED -- as you mention we already have a dedicated test for the inverse behavior.

// UNSUPPORTED: (c++11 || c++14 || c++17 || c++20) && !android

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
// UNSUPPORTED: no-threads
// REQUIRES: c++03 || c++11 || c++14 || c++17 || c++20

// On Android, libc++'s <stdatomic.h> header always redirects to <atomic>, even before C++23.
// XFAIL: android

// No diagnostic gets emitted when we build with modules.
// XFAIL: clang-modules-build

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
// doesn't work at all if we don't use the <stdatomic.h> provided by libc++ in C++23 and above.
// XFAIL: (c++11 || c++14 || c++17 || c++20) && gcc

// On Android, libc++'s <stdatomic.h> header always redirects to <atomic>, even before C++23.
// XFAIL: android

#include <atomic>
#include <stdatomic.h>
#include <type_traits>
Expand Down
Loading