[clang] 01b2554 - [clang] - Add missing builtin name to AtomicExpr JSON dump
via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 25 00:18:32 PDT 2023
Author: serge-sans-paille
Date: 2023-08-25T09:18:18+02:00
New Revision: 01b2554ff4defce979b16d794c13ea99f2e2c155
URL: https://github.com/llvm/llvm-project/commit/01b2554ff4defce979b16d794c13ea99f2e2c155
DIFF: https://github.com/llvm/llvm-project/commit/01b2554ff4defce979b16d794c13ea99f2e2c155.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 target fully specified.
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..2985117ea4e3db
--- /dev/null
+++ b/clang/test/AST/ast-dump-atomic-json.c
@@ -0,0 +1,128 @@
+// 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 been autogenerated by gen_ast_dump_json_test.py
+// using --filters=AtomicExpr
+
+
+// CHECK-NOT: {{^}}Dumping
+// CHECK: "kind": "AtomicExpr",
+// CHECK-NEXT: "range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT: "offset": 125,
+// CHECK-NEXT: "col": 10,
+// CHECK-NEXT: "tokLen": 15
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT: "offset": 162,
+// CHECK-NEXT: "col": 47,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: }
+// CHECK-NEXT: },
+// CHECK-NEXT: "type": {
+// CHECK-NEXT: "qualType": "int"
+// CHECK-NEXT: },
+// CHECK-NEXT: "valueCategory": "prvalue",
+// CHECK-NEXT: "name": "__atomic_load_n",
+// CHECK-NEXT: "inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "ImplicitCastExpr",
+// CHECK-NEXT: "range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT: "offset": 141,
+// CHECK-NEXT: "col": 26,
+// CHECK-NEXT: "tokLen": 3
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT: "offset": 141,
+// CHECK-NEXT: "col": 26,
+// CHECK-NEXT: "tokLen": 3
+// CHECK-NEXT: }
+// CHECK-NEXT: },
+// CHECK-NEXT: "type": {
+// CHECK-NEXT: "qualType": "int *"
+// CHECK-NEXT: },
+// CHECK-NEXT: "valueCategory": "prvalue",
+// CHECK-NEXT: "castKind": "LValueToRValue",
+// CHECK-NEXT: "inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "DeclRefExpr",
+// CHECK-NEXT: "range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT: "offset": 141,
+// CHECK-NEXT: "col": 26,
+// CHECK-NEXT: "tokLen": 3
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT: "offset": 141,
+// CHECK-NEXT: "col": 26,
+// CHECK-NEXT: "tokLen": 3
+// CHECK-NEXT: }
+// CHECK-NEXT: },
+// CHECK-NEXT: "type": {
+// CHECK-NEXT: "qualType": "int *"
+// CHECK-NEXT: },
+// CHECK-NEXT: "valueCategory": "lvalue",
+// CHECK-NEXT: "referencedDecl": {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "ParmVarDecl",
+// CHECK-NEXT: "name": "ptr",
+// CHECK-NEXT: "type": {
+// CHECK-NEXT: "qualType": "int *"
+// CHECK-NEXT: }
+// CHECK-NEXT: }
+// CHECK-NEXT: }
+// CHECK-NEXT: ]
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "IntegerLiteral",
+// CHECK-NEXT: "range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT: "spellingLoc": {
+// CHECK-NEXT: "offset": 417,
+// CHECK-NEXT: "file": "<built-in>",
+// CHECK-NEXT: "line": 13,
+// CHECK-NEXT: "presumedLine": 12,
+// CHECK-NEXT: "col": 26,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: },
+// CHECK-NEXT: "expansionLoc": {
+// CHECK-NEXT: "offset": 146,
+// CHECK-NEXT: "file": "{{.*}}",
+// CHECK-NEXT: "line": 4,
+// CHECK-NEXT: "col": 31,
+// CHECK-NEXT: "tokLen": 16
+// CHECK-NEXT: }
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT: "spellingLoc": {
+// CHECK-NEXT: "offset": 417,
+// CHECK-NEXT: "file": "<built-in>",
+// CHECK-NEXT: "line": 13,
+// CHECK-NEXT: "presumedLine": 12,
+// CHECK-NEXT: "col": 26,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: },
+// CHECK-NEXT: "expansionLoc": {
+// CHECK-NEXT: "offset": 146,
+// CHECK-NEXT: "file": "{{.*}}",
+// CHECK-NEXT: "line": 4,
+// CHECK-NEXT: "col": 31,
+// CHECK-NEXT: "tokLen": 16
+// CHECK-NEXT: }
+// CHECK-NEXT: }
+// CHECK-NEXT: },
+// CHECK-NEXT: "type": {
+// CHECK-NEXT: "qualType": "int"
+// CHECK-NEXT: },
+// CHECK-NEXT: "valueCategory": "prvalue",
+// CHECK-NEXT: "value": "5"
+// CHECK-NEXT: }
+// CHECK-NEXT: ]
+// CHECK-NEXT: }
More information about the cfe-commits
mailing list