Skip to content

Commit ef57b93

Browse files
committed
UPSTREAM: [Clang][AST] Fix printing for atomic_test_and_set and atomic_clear (#159712)
llvm/llvm-project#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 ba49062914f01f68cf3c4e067139a24b29a0e45b)
1 parent 271cac7 commit ef57b93

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

interpreter/llvm-project/clang/docs/ReleaseNotes.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,15 @@ ABI Changes in This Version
257257
AST Dumping Potentially Breaking Changes
258258
----------------------------------------
259259

260+
- Pretty-printing of atomic builtins ``__atomic_test_and_set`` and ``__atomic_clear`` in ``-ast-print`` output.
261+
These previously displayed an extra ``<null expr>`` argument, e.g.:
262+
263+
``__atomic_test_and_set(p, <null expr>, 0)``
264+
265+
Now they are printed as:
266+
267+
``__atomic_test_and_set(p, 0)``
268+
260269
Clang Frontend Potentially Breaking Changes
261270
-------------------------------------------
262271

interpreter/llvm-project/clang/include/clang/AST/Expr.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6783,6 +6783,21 @@ class AtomicExpr : public Expr {
67836783
getOp() == AO__scoped_atomic_compare_exchange_n;
67846784
}
67856785

6786+
bool hasVal1Operand() const {
6787+
switch (getOp()) {
6788+
case AO__atomic_load_n:
6789+
case AO__scoped_atomic_load_n:
6790+
case AO__c11_atomic_load:
6791+
case AO__opencl_atomic_load:
6792+
case AO__hip_atomic_load:
6793+
case AO__atomic_test_and_set:
6794+
case AO__atomic_clear:
6795+
return false;
6796+
default:
6797+
return true;
6798+
}
6799+
}
6800+
67866801
bool isOpenCL() const {
67876802
return getOp() >= AO__opencl_atomic_compare_exchange_strong &&
67886803
getOp() <= AO__opencl_atomic_store;

interpreter/llvm-project/clang/lib/AST/StmtPrinter.cpp

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

19771977
// AtomicExpr stores its subexpressions in a permuted order.
19781978
PrintExpr(Node->getPtr());
1979-
if (Node->getOp() != AtomicExpr::AO__c11_atomic_load &&
1980-
Node->getOp() != AtomicExpr::AO__atomic_load_n &&
1981-
Node->getOp() != AtomicExpr::AO__scoped_atomic_load_n &&
1982-
Node->getOp() != AtomicExpr::AO__opencl_atomic_load &&
1983-
Node->getOp() != AtomicExpr::AO__hip_atomic_load) {
1979+
if (Node->hasVal1Operand()) {
19841980
OS << ", ";
19851981
PrintExpr(Node->getVal1());
19861982
}

0 commit comments

Comments
 (0)