Skip to content

Commit 4198576

Browse files
[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
1 parent 8514d20 commit 4198576

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

clang/include/clang/AST/Expr.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6480,6 +6480,15 @@ class AtomicExpr : public Expr {
64806480
QualType getValueType() const;
64816481

64826482
AtomicOp getOp() const { return Op; }
6483+
StringRef getOpAsString() const {
6484+
switch (Op) {
6485+
#define BUILTIN(ID, TYPE, ATTRS)
6486+
#define ATOMIC_BUILTIN(ID, TYPE, ATTRS) \
6487+
case AO##ID: \
6488+
return #ID;
6489+
#include "clang/Basic/Builtins.def"
6490+
}
6491+
}
64836492
unsigned getNumSubExprs() const { return NumSubExprs; }
64846493

64856494
Expr **getSubExprs() { return reinterpret_cast<Expr **>(SubExprs); }

clang/include/clang/AST/JSONNodeDumper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ class JSONNodeDumper
285285
void VisitBinaryOperator(const BinaryOperator *BO);
286286
void VisitCompoundAssignOperator(const CompoundAssignOperator *CAO);
287287
void VisitMemberExpr(const MemberExpr *ME);
288+
void VisitAtomicExpr(const AtomicExpr *AE);
288289
void VisitCXXNewExpr(const CXXNewExpr *NE);
289290
void VisitCXXDeleteExpr(const CXXDeleteExpr *DE);
290291
void VisitCXXThisExpr(const CXXThisExpr *TE);

clang/lib/AST/JSONNodeDumper.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,10 @@ void JSONNodeDumper::VisitBlockDecl(const BlockDecl *D) {
11791179
attributeOnlyIfTrue("capturesThis", D->capturesCXXThis());
11801180
}
11811181

1182+
void JSONNodeDumper::VisitAtomicExpr(const AtomicExpr *AE) {
1183+
JOS.attribute("name", AE->getOpAsString());
1184+
}
1185+
11821186
void JSONNodeDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *OEE) {
11831187
JOS.attribute("encodedType", createQualType(OEE->getEncodedType()));
11841188
}

clang/test/AST/ast-dump-atomic-json.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// RUN: %clang_cc1 -triple x86_64-pc-linux -Wno-unused-value -ast-dump=json %s | FileCheck %s
2+
3+
int foo(int * ptr) {
4+
return __atomic_load_n(ptr, __ATOMIC_SEQ_CST);
5+
}
6+
7+
// NOTE: CHECK lines have *not* been autogenerated by gen_ast_dump_json_test.py
8+
// as its output is not portable for AtomicExpr across platforms. Instead rely
9+
// on loose CHECKS.
10+
11+
12+
// CHECK-NOT: {{^}}Dumping
13+
// CHECK: "kind": "AtomicExpr",
14+
// CHECK: "type": {
15+
// CHECK: "qualType": "int"
16+
// CHECK: },
17+
// CHECK: "valueCategory": "prvalue",
18+
// CHECK: "name": "__atomic_load_n",
19+
// CHECK: "inner": [
20+
// CHECK: {
21+
// CHECK: "id": "0x{{.*}}",
22+
// CHECK: "kind": "ImplicitCastExpr",
23+
// CHECK: },
24+
// CHECK: "type": {
25+
// CHECK: "qualType": "int *"
26+
// CHECK: },
27+
// CHECK: "valueCategory": "prvalue",
28+
// CHECK: "castKind": "LValueToRValue",
29+
// CHECK: "inner": [
30+
// CHECK: {
31+
// CHECK: "id": "0x{{.*}}",
32+
// CHECK: "kind": "DeclRefExpr",
33+
// CHECK: },
34+
// CHECK: "type": {
35+
// CHECK: "qualType": "int *"
36+
// CHECK: },
37+
// CHECK: "valueCategory": "lvalue",
38+
// CHECK: "referencedDecl": {
39+
// CHECK: "id": "0x{{.*}}",
40+
// CHECK: "kind": "ParmVarDecl",
41+
// CHECK: "name": "ptr",
42+
// CHECK: "type": {
43+
// CHECK: "qualType": "int *"
44+
// CHECK: }
45+
// CHECK: }
46+
// CHECK: }
47+
// CHECK: ]
48+
// CHECK: },
49+
// CHECK: {
50+
// CHECK: "id": "0x{{.*}}",
51+
// CHECK: "kind": "IntegerLiteral",
52+
// CHECK: },
53+
// CHECK: "type": {
54+
// CHECK: "qualType": "int"
55+
// CHECK: },
56+
// CHECK: "valueCategory": "prvalue",
57+
// CHECK: "value": "5"
58+
// CHECK: }
59+
// CHECK: ]
60+
// CHECK: }

0 commit comments

Comments
 (0)