[clang] [Clang][AST] Fix printing for `atomic_test_and_set` and `atomic_clear` (PR #159712)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 19 00:14:52 PDT 2025
https://github.com/devajithvs created https://github.com/llvm/llvm-project/pull/159712
https://github.com/llvm/llvm-project/pull/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.
>From bb99282f4438c0782b0f156a18e2b7604f78c2f3 Mon Sep 17 00:00:00 2001
From: Devajith Valaparambil Sreeramaswamy
<devajith.valaparambil.sreeramaswamy at cern.ch>
Date: Thu, 18 Sep 2025 17:21:45 +0200
Subject: [PATCH] [Clang][AST] Fix printing for `atomic_test_and_set` and
`atomic_clear`
https://github.com/llvm/llvm-project/pull/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.
---
clang/lib/AST/StmtPrinter.cpp | 4 +++-
clang/test/SemaCXX/ast-print.cpp | 11 +++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
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 *();
More information about the cfe-commits
mailing list