Skip to content

Commit

Permalink
[clang] - Add missing builtin name to AtomicExpr JSON dump
Browse files Browse the repository at this point in the history
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
  • Loading branch information
serge-sans-paille committed Aug 28, 2023
1 parent 8514d20 commit 4198576
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
9 changes: 9 additions & 0 deletions clang/include/clang/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/AST/JSONNodeDumper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/AST/JSONNodeDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down
60 changes: 60 additions & 0 deletions clang/test/AST/ast-dump-atomic-json.c
Original file line number Diff line number Diff line change
@@ -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: }

0 comments on commit 4198576

Please sign in to comment.