[clang] 4198576 - [clang] - Add missing builtin name to AtomicExpr JSON dump
via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 27 21:35:08 PDT 2023
Author: serge-sans-paille
Date: 2023-08-28T06:34:57+02:00
New Revision: 4198576157bfd0d08c08b784220d6132b709ae2c
URL: https://github.com/llvm/llvm-project/commit/4198576157bfd0d08c08b784220d6132b709ae2c
DIFF: https://github.com/llvm/llvm-project/commit/4198576157bfd0d08c08b784220d6132b709ae2c.diff
LOG: [clang] - Add missing builtin name to AtomicExpr JSON dump
As a side effect, introduce AtomicExpr::getOpAsString() to dump the
AtomicOp string representation.
This is a recommit with the ranges unchecked to cope with
platform-specific values.
Differential Revision: https://reviews.llvm.org/D158558
Added:
clang/test/AST/ast-dump-atomic-json.c
Modified:
clang/include/clang/AST/Expr.h
clang/include/clang/AST/JSONNodeDumper.h
clang/lib/AST/JSONNodeDumper.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 6737721e1ed1b2..8d1235be78a4ad 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -6480,6 +6480,15 @@ class AtomicExpr : public Expr {
QualType getValueType() const;
AtomicOp getOp() const { return Op; }
+ StringRef getOpAsString() const {
+ switch (Op) {
+#define BUILTIN(ID, TYPE, ATTRS)
+#define ATOMIC_BUILTIN(ID, TYPE, ATTRS) \
+ case AO##ID: \
+ return #ID;
+#include "clang/Basic/Builtins.def"
+ }
+ }
unsigned getNumSubExprs() const { return NumSubExprs; }
Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); }
diff --git a/clang/include/clang/AST/JSONNodeDumper.h b/clang/include/clang/AST/JSONNodeDumper.h
index 0ce272df8df65b..4def5389137fa4 100644
--- a/clang/include/clang/AST/JSONNodeDumper.h
+++ b/clang/include/clang/AST/JSONNodeDumper.h
@@ -285,6 +285,7 @@ class JSONNodeDumper
void VisitBinaryOperator(const BinaryOperator *BO);
void VisitCompoundAssignOperator(const CompoundAssignOperator *CAO);
void VisitMemberExpr(const MemberExpr *ME);
+ void VisitAtomicExpr(const AtomicExpr *AE);
void VisitCXXNewExpr(const CXXNewExpr *NE);
void VisitCXXDeleteExpr(const CXXDeleteExpr *DE);
void VisitCXXThisExpr(const CXXThisExpr *TE);
diff --git a/clang/lib/AST/JSONNodeDumper.cpp b/clang/lib/AST/JSONNodeDumper.cpp
index 139dfce41e914c..e67c2c7e216dce 100644
--- a/clang/lib/AST/JSONNodeDumper.cpp
+++ b/clang/lib/AST/JSONNodeDumper.cpp
@@ -1179,6 +1179,10 @@ void JSONNodeDumper::VisitBlockDecl(const BlockDecl *D) {
attributeOnlyIfTrue("capturesThis", D->capturesCXXThis());
}
+void JSONNodeDumper::VisitAtomicExpr(const AtomicExpr *AE) {
+ JOS.attribute("name", AE->getOpAsString());
+}
+
void JSONNodeDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *OEE) {
JOS.attribute("encodedType", createQualType(OEE->getEncodedType()));
}
diff --git a/clang/test/AST/ast-dump-atomic-json.c b/clang/test/AST/ast-dump-atomic-json.c
new file mode 100644
index 00000000000000..fa236cee25a1bd
--- /dev/null
+++ b/clang/test/AST/ast-dump-atomic-json.c
@@ -0,0 +1,60 @@
+// RUN: %clang_cc1 -triple x86_64-pc-linux -Wno-unused-value -ast-dump=json %s | FileCheck %s
+
+int foo(int * ptr) {
+ return __atomic_load_n(ptr, __ATOMIC_SEQ_CST);
+}
+
+// NOTE: CHECK lines have *not* been autogenerated by gen_ast_dump_json_test.py
+// as its output is not portable for AtomicExpr across platforms. Instead rely
+// on loose CHECKS.
+
+
+// CHECK-NOT: {{^}}Dumping
+// CHECK: "kind": "AtomicExpr",
+// CHECK: "type": {
+// CHECK: "qualType": "int"
+// CHECK: },
+// CHECK: "valueCategory": "prvalue",
+// CHECK: "name": "__atomic_load_n",
+// CHECK: "inner": [
+// CHECK: {
+// CHECK: "id": "0x{{.*}}",
+// CHECK: "kind": "ImplicitCastExpr",
+// CHECK: },
+// CHECK: "type": {
+// CHECK: "qualType": "int *"
+// CHECK: },
+// CHECK: "valueCategory": "prvalue",
+// CHECK: "castKind": "LValueToRValue",
+// CHECK: "inner": [
+// CHECK: {
+// CHECK: "id": "0x{{.*}}",
+// CHECK: "kind": "DeclRefExpr",
+// CHECK: },
+// CHECK: "type": {
+// CHECK: "qualType": "int *"
+// CHECK: },
+// CHECK: "valueCategory": "lvalue",
+// CHECK: "referencedDecl": {
+// CHECK: "id": "0x{{.*}}",
+// CHECK: "kind": "ParmVarDecl",
+// CHECK: "name": "ptr",
+// CHECK: "type": {
+// CHECK: "qualType": "int *"
+// CHECK: }
+// CHECK: }
+// CHECK: }
+// CHECK: ]
+// CHECK: },
+// CHECK: {
+// CHECK: "id": "0x{{.*}}",
+// CHECK: "kind": "IntegerLiteral",
+// CHECK: },
+// CHECK: "type": {
+// CHECK: "qualType": "int"
+// CHECK: },
+// CHECK: "valueCategory": "prvalue",
+// CHECK: "value": "5"
+// CHECK: }
+// CHECK: ]
+// CHECK: }
More information about the cfe-commits
mailing list