Skip to content

Commit b9bbe57

Browse files
committed
[Clang][AST] Fix printing for atomic_test_and_set and atomic_clear
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.
1 parent ae1e909 commit b9bbe57

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ AST Dumping Potentially Breaking Changes
114114
----------------------------------------
115115
- How nested name specifiers are dumped and printed changes, keeping track of clang AST changes.
116116

117+
- Pretty-printing of atomic builtins ``__atomic_test_and_set`` and ``__atomic_clear`` in ``-ast-print`` output.
118+
These previously displayed an extra ``<null expr>`` argument, e.g.:
119+
120+
``__atomic_test_and_set(p, <null expr>, 0)``
121+
122+
Now they are printed as:
123+
124+
``__atomic_test_and_set(p, 0)``
125+
117126
Clang Frontend Potentially Breaking Changes
118127
-------------------------------------------
119128
- Members of anonymous unions/structs are now injected as ``IndirectFieldDecl``

clang/include/clang/AST/Expr.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6908,6 +6908,21 @@ class AtomicExpr : public Expr {
69086908
getOp() == AO__scoped_atomic_compare_exchange_n;
69096909
}
69106910

6911+
bool hasVal1Operand() const {
6912+
switch (getOp()) {
6913+
case AO__atomic_load_n:
6914+
case AO__scoped_atomic_load_n:
6915+
case AO__c11_atomic_load:
6916+
case AO__opencl_atomic_load:
6917+
case AO__hip_atomic_load:
6918+
case AO__atomic_test_and_set:
6919+
case AO__atomic_clear:
6920+
return false;
6921+
default:
6922+
return true;
6923+
}
6924+
}
6925+
69116926
bool isOpenCL() const {
69126927
return getOp() >= AO__opencl_atomic_compare_exchange_strong &&
69136928
getOp() <= AO__opencl_atomic_store;

clang/lib/AST/StmtPrinter.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,11 +2024,7 @@ void StmtPrinter::VisitAtomicExpr(AtomicExpr *Node) {
20242024

20252025
// AtomicExpr stores its subexpressions in a permuted order.
20262026
PrintExpr(Node->getPtr());
2027-
if (Node->getOp() != AtomicExpr::AO__c11_atomic_load &&
2028-
Node->getOp() != AtomicExpr::AO__atomic_load_n &&
2029-
Node->getOp() != AtomicExpr::AO__scoped_atomic_load_n &&
2030-
Node->getOp() != AtomicExpr::AO__opencl_atomic_load &&
2031-
Node->getOp() != AtomicExpr::AO__hip_atomic_load) {
2027+
if (Node->hasVal1Operand()) {
20322028
OS << ", ";
20332029
PrintExpr(Node->getVal1());
20342030
}

0 commit comments

Comments
 (0)