[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
This commit is contained in:
serge-sans-paille 2023-08-22 23:33:33 +02:00
parent 615d812696
commit 01b2554ff4
No known key found for this signature in database
GPG Key ID: 7B24DA8C9551659F
4 changed files with 142 additions and 0 deletions

View File

@ -6480,6 +6480,15 @@ public:
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); }

View File

@ -285,6 +285,7 @@ public:
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);

View File

@ -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()));
}

View File

@ -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: }