-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[clang] Define ATOMIC_FLAG_INIT
correctly for C++.
#97534
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
Conversation
@llvm/pr-subscribers-backend-x86 @llvm/pr-subscribers-clang Author: Chris Copeland (chrisnc) ChangesFull diff: https://github.com/llvm/llvm-project/pull/97534.diff 2 Files Affected:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1537eaaba0c66..3d85065a7ff8a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -750,6 +750,8 @@ Bug Fixes in This Version
- Fixed `static_cast` to array of unknown bound. Fixes (#GH62863).
+- Fixed the definition of ATOMIC_FLAG_INIT in stdatomic.h so it can be used in C++.
+
Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Headers/stdatomic.h b/clang/lib/Headers/stdatomic.h
index 9c103d98af8c5..88172038be5c4 100644
--- a/clang/lib/Headers/stdatomic.h
+++ b/clang/lib/Headers/stdatomic.h
@@ -166,7 +166,11 @@ typedef _Atomic(uintmax_t) atomic_uintmax_t;
typedef struct atomic_flag { atomic_bool _Value; } atomic_flag;
+#ifdef __cplusplus
+#define ATOMIC_FLAG_INIT { false }
+#else
#define ATOMIC_FLAG_INIT { 0 }
+#endif
/* These should be provided by the libc implementation. */
#ifdef __cplusplus
|
Without this change, trying to use https://godbolt.org/z/sTvMs5a95
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
34a618e
to
b7857c2
Compare
ping |
1 similar comment
ping |
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.
Thank you for catching this! Can you also add some tests to clang/test/Headers/
? We have some coverage for stdatomic.h in C, but not in C++ (I'd recommend trying to add a RUN
line to the .c file with -x c++
so it's tested in C++ mode and then ensure there's sufficient coverage for ATOMIC_FLAG_INIT
.)
b7857c2
to
1b39c59
Compare
Rebased and added a test case. I confirmed that the test fails using the current definition of
|
ATOMIC_FLAG_INIT
correctly for C++.
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.
LGTM!
Btw, do you need someone to merge this on your behalf? |
@AaronBallman yes, that would be great! I'm just a contributor, not a collaborator. |
I think this should be picked for the Clang 19 branch, so I filed #100362 |
(cherry picked from commit 4bb3a1e)
(cherry picked from commit 4bb3a1e)
@AaronBallman Just FYI you can also add the Milestone to the PR directly and use the /cherry-pick command right here. This is a bit simpler. |
Error: Command failed due to missing milestone. |
It seems like the bot looks for the command anywhere in any comment :) |
That's good to know! I was going off the documentation at: https://www.llvm.org/docs/GitHub.html#backporting-fixes-to-the-release-branches because it says "issue" specifically. I'll post a patch to update those docs, thanks! |
|
Error: Command failed due to missing milestone. |
Error: Command failed due to missing milestone. |
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60250653
(cherry picked from commit 4bb3a1e)
No description provided.