-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[Clang][AST] Fix printing for atomic_test_and_set and atomic_clear
#159712
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-clang Author: Devajith (devajithvs) Changes#121943 rewrote StmtPrinter::VisitAtomicExpr still treated them like other atomic builtins with a Val1 operand. This led to incorrect pretty-printing when dumping the AST. Skip Val1 for these two builtins like atomic loads. Full diff: https://github.com/llvm/llvm-project/pull/159712.diff 2 Files Affected:
diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp
index 0030300521128..8f348f6e5bc73 100644
--- a/clang/lib/AST/StmtPrinter.cpp
+++ b/clang/lib/AST/StmtPrinter.cpp
@@ -2028,7 +2028,9 @@ void StmtPrinter::VisitAtomicExpr(AtomicExpr *Node) {
Node->getOp() != AtomicExpr::AO__atomic_load_n &&
Node->getOp() != AtomicExpr::AO__scoped_atomic_load_n &&
Node->getOp() != AtomicExpr::AO__opencl_atomic_load &&
- Node->getOp() != AtomicExpr::AO__hip_atomic_load) {
+ Node->getOp() != AtomicExpr::AO__hip_atomic_load &&
+ Node->getOp() != AtomicExpr::AO__atomic_test_and_set &&
+ Node->getOp() != AtomicExpr::AO__atomic_clear) {
OS << ", ";
PrintExpr(Node->getVal1());
}
diff --git a/clang/test/SemaCXX/ast-print.cpp b/clang/test/SemaCXX/ast-print.cpp
index 2cb1ec440b6bb..2dc32c20b7296 100644
--- a/clang/test/SemaCXX/ast-print.cpp
+++ b/clang/test/SemaCXX/ast-print.cpp
@@ -176,6 +176,17 @@ float test15() {
return __builtin_asinf(1.0F);
}
+// CHECK: void test16() {
+// CHECK: char *ptr;
+// CHECK: __atomic_test_and_set(ptr, 0);
+// CHECK: __atomic_clear(ptr, 0);
+// CHECK: }
+void test16() {
+ char *ptr;
+ __atomic_test_and_set(ptr, 0);
+ __atomic_clear(ptr, 0);
+}
+
namespace PR18776 {
struct A {
operator void *();
|
|
We currently print: $ echo 'char *a; void b() { __atomic_test_and_set(a, 0);}' | clang -cc1 -ast-print
char *a;
void b() {
__atomic_test_and_set(a, <null expr>, 0);
}This was probably missed in #121943 Discovered when debugging issues upgrading ROOT/Cling to LLVM20: root-project/root#19242 CC: @ostannard, @shafik, @jyknight |
cor3ntin
left a comment
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.
This change needs a release note.
Please add an entry to clang/docs/ReleaseNotes.rst in the section the most adapted to the change, and referencing any Github issue this change fixes. Thanks!
clang/test/SemaCXX/ast-print.cpp
Outdated
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.
Do we have tests for the other atomic load builtins? It might be worth checking them all
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.
Added test cases for all operations in: https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html
clang/lib/AST/StmtPrinter.cpp
Outdated
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.
Are there other places we do a similar check? Maybe we need that to me a member function of AtomicExpr
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.
Yes, we do a similar check here, but it is part of a bigger switch case.
llvm-project/clang/lib/CodeGen/CGAtomic.cpp
Lines 904 to 911 in fba55c8
| case AtomicExpr::AO__atomic_load_n: | |
| case AtomicExpr::AO__scoped_atomic_load_n: | |
| case AtomicExpr::AO__c11_atomic_load: | |
| case AtomicExpr::AO__opencl_atomic_load: | |
| case AtomicExpr::AO__hip_atomic_load: | |
| case AtomicExpr::AO__atomic_test_and_set: | |
| case AtomicExpr::AO__atomic_clear: | |
| break; |
llvm#121943 rewrote `__atomic_test_and_set` and `__atomic_clear` to be lowered through AtomicExpr StmtPrinter::VisitAtomicExpr still treated them like other atomic builtins with a Val1 operand. This led to incorrect pretty-printing when dumping the AST. Skip Val1 for these two builtins like atomic loads.
bb99282 to
f2e9987
Compare
cor3ntin
left a comment
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
|
Thanks for reviewing @cor3ntin. Would you mind merging this? (I don't have commit access yet) |
…omic_clear` (llvm#159712) llvm#121943 rewrote `__atomic_test_and_set` and `__atomic_clear` to be lowered through AtomicExpr StmtPrinter::VisitAtomicExpr still treated them like other atomic builtins with a Val1 operand. This led to incorrect pretty-printing when dumping the AST. Skip Val1 for these two builtins like atomic loads. (cherry picked from commit ba49062)
…omic_clear` (llvm#159712) llvm#121943 rewrote `__atomic_test_and_set` and `__atomic_clear` to be lowered through AtomicExpr StmtPrinter::VisitAtomicExpr still treated them like other atomic builtins with a Val1 operand. This led to incorrect pretty-printing when dumping the AST. Skip Val1 for these two builtins like atomic loads. (cherry picked from commit ba49062)
#121943 rewrote
__atomic_test_and_setand__atomic_clearto be lowered through AtomicExprStmtPrinter::VisitAtomicExpr still treated them like other atomic builtins with a Val1 operand. This led to incorrect pretty-printing when dumping the AST.
Skip Val1 for these two builtins like atomic loads.