-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[libc++] Don't implement <stdatomic.h> before C++23 #123130
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
libcxx/test/libcxx/atomics/atomics.syn/incompatible_with_stdatomic.verify.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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.}} |
24 changes: 24 additions & 0 deletions
24
libcxx/test/libcxx/atomics/stdatomic.h.syn/dont_hijack_header.compile.pass.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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; | ||
| } |
25 changes: 25 additions & 0 deletions
25
libcxx/test/libcxx/atomics/stdatomic.h.syn/dont_hijack_header.cxx23.compile.pass.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 | ||
| // XFAIL: FROZEN-CXX03-HEADERS-FIXME | ||
|
|
||
| // 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 | ||
|
|
||
| #include <atomic> | ||
| #include <stdatomic.h> | ||
| #include <type_traits> | ||
|
|
||
| static_assert(!std::is_same<_Atomic(int), std::atomic<int> >::value, ""); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW: Android might be better served by checking for a macro like
kill_dependencyoratomic_loadinstead of_LIBCPP_STDATOMIC_H. (The previous version of this compatibility check looked forkill_dependency. #83351) Usingkill_dependencyoratomic_load, the Bionicstdatomic.hand the libc++atomicheaders could be included simultaneously.The Android/Bionic stdatomic.h never defines
kill_dependency. It does defineatomic_loadfor the C dialect, but for C++, it does not defineatomic_load, because it delegates toatomicinstead and has ausing std::atomic_load;declaration. (The Bionicstdatomic.hhas delegated toatomicsince 2014 and was the inspiration for the current C++23 behavior.)Maybe it's possible for Bionic to drop its C++ support from its
stdatomic.h, by switching users to C++23 instead. That seems like a good goal in the long-run. I think Android can carry a local LLVM patch, though, too, if we need to.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please let me know what you think about the latest update.