| From f9a1f3b7e70d960338b255e376741417fc52cb92 Mon Sep 17 00:00:00 2001 |
| From: Yi Kong <yikong@google.com> |
| Date: Wed, 22 Jan 2025 14:03:48 +0800 |
| Subject: [PATCH] Revert "[libc++] Don't implement <stdatomic.h> before C++23 |
| (#123130)" |
| |
| This reverts commit bbd871e2baad2e74dbde202823b3439d2a96d3f8. |
| --- |
| libcxx/include/atomic | 10 ------- |
| libcxx/include/stdatomic.h | 10 ++----- |
| ...compatible_with_stdatomic.compile.pass.cpp | 11 ++++---- |
| .../incompatible_with_stdatomic.verify.cpp | 22 --------------- |
| .../dont_hijack_header.compile.pass.cpp | 24 ---------------- |
| .../dont_hijack_header.cxx23.compile.pass.cpp | 28 ------------------- |
| 6 files changed, 8 insertions(+), 97 deletions(-) |
| delete mode 100644 libcxx/test/libcxx/atomics/atomics.syn/incompatible_with_stdatomic.verify.cpp |
| delete mode 100644 libcxx/test/libcxx/atomics/stdatomic.h.syn/dont_hijack_header.compile.pass.cpp |
| delete mode 100644 libcxx/test/libcxx/atomics/stdatomic.h.syn/dont_hijack_header.cxx23.compile.pass.cpp |
| |
| diff --git a/libcxx/include/atomic b/libcxx/include/atomic |
| index 75af5de33ca4..80f9e437bfaa 100644 |
| --- a/libcxx/include/atomic |
| +++ b/libcxx/include/atomic |
| @@ -592,16 +592,6 @@ template <class T> |
| #else |
| # include <__config> |
| |
| -# if defined(_LIBCPP_STDATOMIC_H) || defined(kill_dependency) || defined(atomic_load) |
| -# define _LIBCPP_STDATOMIC_H_HAS_DEFINITELY_BEEN_INCLUDED 1 |
| -# else |
| -# define _LIBCPP_STDATOMIC_H_HAS_DEFINITELY_BEEN_INCLUDED 0 |
| -# endif |
| - |
| -# if _LIBCPP_STD_VER < 23 && _LIBCPP_STDATOMIC_H_HAS_DEFINITELY_BEEN_INCLUDED |
| -# error <atomic> is incompatible with <stdatomic.h> before C++23. Please compile with -std=c++23. |
| -# endif |
| - |
| # include <__atomic/aliases.h> |
| # include <__atomic/atomic.h> |
| # include <__atomic/atomic_flag.h> |
| diff --git a/libcxx/include/stdatomic.h b/libcxx/include/stdatomic.h |
| index 2991030eee45..a0b46e3b7bc1 100644 |
| --- a/libcxx/include/stdatomic.h |
| +++ b/libcxx/include/stdatomic.h |
| @@ -126,7 +126,7 @@ using std::atomic_signal_fence // see below |
| # pragma GCC system_header |
| # endif |
| |
| -# if defined(__cplusplus) && _LIBCPP_STD_VER >= 23 |
| +# if defined(__cplusplus) |
| |
| # include <atomic> |
| # include <version> |
| @@ -231,17 +231,13 @@ using std::atomic_store_explicit _LIBCPP_USING_IF_EXISTS; |
| using std::atomic_signal_fence _LIBCPP_USING_IF_EXISTS; |
| using std::atomic_thread_fence _LIBCPP_USING_IF_EXISTS; |
| |
| -# elif defined(_LIBCPP_COMPILER_CLANG_BASED) |
| +# else |
| |
| -// Before C++23, we include the next <stdatomic.h> on the path to avoid hijacking |
| -// the header. We do this because Clang has historically shipped a <stdatomic.h> |
| -// header that would be available in all Standard modes, and we don't want to |
| -// break that use case. |
| # if __has_include_next(<stdatomic.h>) |
| # include_next <stdatomic.h> |
| # endif |
| |
| -# endif // defined(__cplusplus) && _LIBCPP_STD_VER >= 23 |
| +# endif // defined(__cplusplus) |
| #endif // defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) |
| |
| #endif // _LIBCPP_STDATOMIC_H |
| 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 30e9672a2568..323072da1446 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,16 +7,15 @@ |
| //===----------------------------------------------------------------------===// |
| |
| // UNSUPPORTED: no-threads |
| -// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 |
| |
| // XFAIL: FROZEN-CXX03-HEADERS-FIXME |
| |
| -// This test verifies that <stdatomic.h> redirects to <atomic>. |
| +// This test verifies that <stdatomic.h> redirects to <atomic>. As an extension, |
| +// libc++ enables this redirection even before C++23. |
| |
| -// Before C++23, <stdatomic.h> can be included after <atomic>, but including it |
| -// first doesn't work because its macros break <atomic>. Fixing that is the point |
| -// of the C++23 change that added <stdatomic.h> to C++. Thus, this test verifies |
| -// that <stdatomic.h> can be included first. |
| +// Ordinarily, <stdatomic.h> can be included after <atomic>, but including it |
| +// first doesn't work because its macros break <atomic>. Verify that |
| +// <stdatomic.h> can be included first. |
| #include <stdatomic.h> |
| #include <atomic> |
| |
| 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 |
| deleted file mode 100644 |
| index ca092d9c6027..000000000000 |
| --- a/libcxx/test/libcxx/atomics/atomics.syn/incompatible_with_stdatomic.verify.cpp |
| +++ /dev/null |
| @@ -1,22 +0,0 @@ |
| -//===----------------------------------------------------------------------===// |
| -// |
| -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| -// See https://llvm.org/LICENSE.txt for license information. |
| -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| -// |
| -//===----------------------------------------------------------------------===// |
| - |
| -// UNSUPPORTED: no-threads |
| -// REQUIRES: c++03 || c++11 || c++14 || c++17 || c++20 |
| - |
| -// This test ensures that we issue a reasonable diagnostic when including <atomic> after |
| -// <stdatomic.h> has been included. Before C++23, this otherwise leads to obscure errors |
| -// because <atomic> may try to redefine things defined by <stdatomic.h>. |
| - |
| -// Ignore additional weird errors that happen when the two headers are mixed. |
| -// ADDITIONAL_COMPILE_FLAGS: -Xclang -verify-ignore-unexpected=error -Xclang -verify-ignore-unexpected=warning |
| - |
| -#include <stdatomic.h> |
| -#include <atomic> |
| - |
| -// expected-error@*:* {{<atomic> is incompatible with <stdatomic.h> before C++23.}} |
| diff --git a/libcxx/test/libcxx/atomics/stdatomic.h.syn/dont_hijack_header.compile.pass.cpp b/libcxx/test/libcxx/atomics/stdatomic.h.syn/dont_hijack_header.compile.pass.cpp |
| deleted file mode 100644 |
| index 6df80daf9414..000000000000 |
| --- a/libcxx/test/libcxx/atomics/stdatomic.h.syn/dont_hijack_header.compile.pass.cpp |
| +++ /dev/null |
| @@ -1,24 +0,0 @@ |
| -//===----------------------------------------------------------------------===// |
| -// |
| -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| -// See https://llvm.org/LICENSE.txt for license information. |
| -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| -// |
| -//===----------------------------------------------------------------------===// |
| - |
| -// UNSUPPORTED: no-threads |
| - |
| -// This test ensures that we don't hijack the <stdatomic.h> header (e.g. by providing |
| -// an empty header) even when compiling before C++23, since some users were using the |
| -// Clang or platform provided header before libc++ added its own. |
| - |
| -// On GCC, the compiler-provided <stdatomic.h> is not C++ friendly, so including <stdatomic.h> |
| -// 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 |
| - |
| -#include <stdatomic.h> |
| - |
| -void f() { |
| - atomic_int i; // just make sure the header isn't empty |
| - (void)i; |
| -} |
| 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 |
| deleted file mode 100644 |
| index a8a99e6937f3..000000000000 |
| --- a/libcxx/test/libcxx/atomics/stdatomic.h.syn/dont_hijack_header.cxx23.compile.pass.cpp |
| +++ /dev/null |
| @@ -1,28 +0,0 @@ |
| -//===----------------------------------------------------------------------===// |
| -// |
| -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| -// See https://llvm.org/LICENSE.txt for license information. |
| -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| -// |
| -//===----------------------------------------------------------------------===// |
| - |
| -// UNSUPPORTED: no-threads |
| - |
| -// This test verifies that <stdatomic.h> DOES NOT redirect to <atomic> before C++23, |
| -// since doing so is a breaking change. Several things can break when that happens, |
| -// because the type of _Atomic(T) changes from _Atomic(T) to std::atomic<T>. |
| -// |
| -// For example, redeclarations can become invalid depending on whether they |
| -// have been declared with <stdatomic.h> in scope or not. |
| - |
| -// REQUIRES: c++03 || c++11 || c++14 || c++17 || c++20 |
| - |
| -// On GCC, the compiler-provided <stdatomic.h> is not C++ friendly, so including <stdatomic.h> |
| -// 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 |
| - |
| -#include <atomic> |
| -#include <stdatomic.h> |
| -#include <type_traits> |
| - |
| -static_assert(!std::is_same<_Atomic(int), std::atomic<int> >::value, ""); |
| -- |
| 2.48.0.rc2.279.g1de40edade-goog |
| |