Dump more information about expressions involving temporaries when dumping the AST to JSON.

llvm-svn: 363943
This commit is contained in:
Aaron Ballman 2019-06-20 16:22:35 +00:00
parent 6ab35c9dc0
commit 1fffe8d6ee
5 changed files with 516 additions and 2 deletions

View File

@ -255,6 +255,9 @@ public:
void VisitGenericSelectionExpr(const GenericSelectionExpr *GSE);
void VisitCXXUnresolvedConstructExpr(const CXXUnresolvedConstructExpr *UCE);
void VisitCXXConstructExpr(const CXXConstructExpr *CE);
void VisitExprWithCleanups(const ExprWithCleanups *EWC);
void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *BTE);
void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *MTE);
void VisitIntegerLiteral(const IntegerLiteral *IL);
void VisitCharacterLiteral(const CharacterLiteral *CL);

View File

@ -1026,6 +1026,51 @@ void JSONNodeDumper::VisitCXXConstructExpr(const CXXConstructExpr *CE) {
}
}
void JSONNodeDumper::VisitExprWithCleanups(const ExprWithCleanups *EWC) {
attributeOnlyIfTrue("cleanupsHaveSideEffects",
EWC->cleanupsHaveSideEffects());
if (EWC->getNumObjects()) {
JOS.attributeArray("cleanups", [this, EWC] {
for (const ExprWithCleanups::CleanupObject &CO : EWC->getObjects())
JOS.value(createBareDeclRef(CO));
});
}
}
void JSONNodeDumper::VisitCXXBindTemporaryExpr(
const CXXBindTemporaryExpr *BTE) {
const CXXTemporary *Temp = BTE->getTemporary();
JOS.attribute("temp", createPointerRepresentation(Temp));
if (const CXXDestructorDecl *Dtor = Temp->getDestructor())
JOS.attribute("dtor", createBareDeclRef(Dtor));
}
void JSONNodeDumper::VisitMaterializeTemporaryExpr(
const MaterializeTemporaryExpr *MTE) {
if (const ValueDecl *VD = MTE->getExtendingDecl())
JOS.attribute("extendingDecl", createBareDeclRef(VD));
switch (MTE->getStorageDuration()) {
case SD_Automatic:
JOS.attribute("storageDuration", "automatic");
break;
case SD_Dynamic:
JOS.attribute("storageDuration", "dynamic");
break;
case SD_FullExpression:
JOS.attribute("storageDuration", "full expression");
break;
case SD_Static:
JOS.attribute("storageDuration", "static");
break;
case SD_Thread:
JOS.attribute("storageDuration", "thread");
break;
}
attributeOnlyIfTrue("boundToLValueRef", MTE->isBoundToLvalueReference());
}
void JSONNodeDumper::VisitIntegerLiteral(const IntegerLiteral *IL) {
JOS.attribute("value",
IL->getValue().toString(

View File

@ -83,6 +83,7 @@ void f() {
__typeof__(B.foo) Test;
}
// CHECK: "kind": "ObjCInterfaceDecl",
// CHECK-NEXT: "loc": {
// CHECK-NEXT: "col": 12,
@ -1492,6 +1493,13 @@ void f() {
// CHECK-NEXT: "qualType": "void (^)(int, ...)"
// CHECK-NEXT: },
// CHECK-NEXT: "valueCategory": "rvalue",
// CHECK-NEXT: "cleanupsHaveSideEffects": true,
// CHECK-NEXT: "cleanups": [
// CHECK-NEXT: {
// CHECK-NEXT: "id": "0x{{.*}}",
// CHECK-NEXT: "kind": "BlockDecl"
// CHECK-NEXT: }
// CHECK-NEXT: ],
// CHECK-NEXT: "inner": [
// CHECK-NEXT: {
// CHECK-NEXT: "id": "0x{{.*}}",
@ -1701,4 +1709,3 @@ void f() {
// CHECK-NEXT: "qualType": "typeof (B.foo)"
// CHECK-NEXT: }
// CHECK-NEXT: }

View File

@ -104,6 +104,13 @@ void TestObjCAtCatchStmt() {
// CHECK-NEXT: "qualType": "void (^)(void)"
// CHECK-NEXT: },
// CHECK-NEXT: "valueCategory": "rvalue",
// CHECK-NEXT: "cleanupsHaveSideEffects": true,
// CHECK-NEXT: "cleanups": [
// CHECK-NEXT: {
// CHECK-NEXT: "id": "0x{{.*}}",
// CHECK-NEXT: "kind": "BlockDecl"
// CHECK-NEXT: }
// CHECK-NEXT: ],
// CHECK-NEXT: "inner": [
// CHECK-NEXT: {
// CHECK-NEXT: "id": "0x{{.*}}",
@ -322,6 +329,13 @@ void TestObjCAtCatchStmt() {
// CHECK-NEXT: "qualType": "void (^)(void)"
// CHECK-NEXT: },
// CHECK-NEXT: "valueCategory": "rvalue",
// CHECK-NEXT: "cleanupsHaveSideEffects": true,
// CHECK-NEXT: "cleanups": [
// CHECK-NEXT: {
// CHECK-NEXT: "id": "0x{{.*}}",
// CHECK-NEXT: "kind": "BlockDecl"
// CHECK-NEXT: }
// CHECK-NEXT: ],
// CHECK-NEXT: "inner": [
// CHECK-NEXT: {
// CHECK-NEXT: "id": "0x{{.*}}",
@ -716,4 +730,3 @@ void TestObjCAtCatchStmt() {
// CHECK-NEXT: }
// CHECK-NEXT: ]
// CHECK-NEXT: }

View File

@ -0,0 +1,446 @@
// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -ast-dump=json %s | FileCheck %s
struct S {
S() {}
~S() {}
};
void func(const int &);
void BindTemp() {
const S &s = S();
}
void MaterializeTemp() {
const int &i = 1.0;
float f = 1.0f;
func(f);
}
// CHECK: "kind": "ExprWithCleanups",
// CHECK-NEXT: "range": {
// CHECK-NEXT: "begin": {
// CHECK-NEXT: "col": 16,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 11
// CHECK-NEXT: },
// CHECK-NEXT: "end": {
// CHECK-NEXT: "col": 18,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 11
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "type": {
// CHECK-NEXT: "qualType": "const S"
// CHECK-NEXT: },
// CHECK-NEXT: "valueCategory": "lvalue",
// CHECK-NEXT: "cleanupsHaveSideEffects": true,
// CHECK-NEXT: "inner": [
// CHECK-NEXT: {
// CHECK-NEXT: "id": "0x{{.*}}",
// CHECK-NEXT: "kind": "MaterializeTemporaryExpr",
// CHECK-NEXT: "range": {
// CHECK-NEXT: "begin": {
// CHECK-NEXT: "col": 16,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 11
// CHECK-NEXT: },
// CHECK-NEXT: "end": {
// CHECK-NEXT: "col": 18,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 11
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "type": {
// CHECK-NEXT: "qualType": "const S"
// CHECK-NEXT: },
// CHECK-NEXT: "valueCategory": "lvalue",
// CHECK-NEXT: "extendingDecl": {
// CHECK-NEXT: "id": "0x{{.*}}",
// CHECK-NEXT: "kind": "VarDecl",
// CHECK-NEXT: "name": "s",
// CHECK-NEXT: "type": {
// CHECK-NEXT: "qualType": "const S &"
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "storageDuration": "automatic",
// CHECK-NEXT: "boundToLValueRef": true,
// CHECK-NEXT: "inner": [
// CHECK-NEXT: {
// CHECK-NEXT: "id": "0x{{.*}}",
// CHECK-NEXT: "kind": "ImplicitCastExpr",
// CHECK-NEXT: "range": {
// CHECK-NEXT: "begin": {
// CHECK-NEXT: "col": 16,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 11
// CHECK-NEXT: },
// CHECK-NEXT: "end": {
// CHECK-NEXT: "col": 18,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 11
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "type": {
// CHECK-NEXT: "qualType": "const S"
// CHECK-NEXT: },
// CHECK-NEXT: "valueCategory": "rvalue",
// CHECK-NEXT: "castKind": "NoOp",
// CHECK-NEXT: "inner": [
// CHECK-NEXT: {
// CHECK-NEXT: "id": "0x{{.*}}",
// CHECK-NEXT: "kind": "CXXBindTemporaryExpr",
// CHECK-NEXT: "range": {
// CHECK-NEXT: "begin": {
// CHECK-NEXT: "col": 16,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 11
// CHECK-NEXT: },
// CHECK-NEXT: "end": {
// CHECK-NEXT: "col": 18,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 11
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "type": {
// CHECK-NEXT: "qualType": "S"
// CHECK-NEXT: },
// CHECK-NEXT: "valueCategory": "rvalue",
// CHECK-NEXT: "temp": "0x{{.*}}",
// CHECK-NEXT: "dtor": {
// CHECK-NEXT: "id": "0x{{.*}}",
// CHECK-NEXT: "kind": "CXXDestructorDecl",
// CHECK-NEXT: "name": "~S",
// CHECK-NEXT: "type": {
// CHECK-NEXT: "qualType": "void () noexcept"
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "inner": [
// CHECK-NEXT: {
// CHECK-NEXT: "id": "0x{{.*}}",
// CHECK-NEXT: "kind": "CXXTemporaryObjectExpr",
// CHECK-NEXT: "range": {
// CHECK-NEXT: "begin": {
// CHECK-NEXT: "col": 16,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 11
// CHECK-NEXT: },
// CHECK-NEXT: "end": {
// CHECK-NEXT: "col": 18,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 11
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "type": {
// CHECK-NEXT: "qualType": "S"
// CHECK-NEXT: },
// CHECK-NEXT: "valueCategory": "rvalue",
// CHECK-NEXT: "ctorType": {
// CHECK-NEXT: "qualType": "void ()"
// CHECK-NEXT: },
// CHECK-NEXT: "hadMultipleCandidates": true,
// CHECK-NEXT: "constructionKind": "complete"
// CHECK-NEXT: }
// CHECK-NEXT: ]
// CHECK-NEXT: }
// CHECK-NEXT: ]
// CHECK-NEXT: }
// CHECK-NEXT: ]
// CHECK-NEXT: }
// CHECK-NEXT: ]
// CHECK-NEXT: }
// CHECK: "kind": "ExprWithCleanups",
// CHECK-NEXT: "range": {
// CHECK-NEXT: "begin": {
// CHECK-NEXT: "col": 18,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 15
// CHECK-NEXT: },
// CHECK-NEXT: "end": {
// CHECK-NEXT: "col": 18,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 15
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "type": {
// CHECK-NEXT: "qualType": "const int"
// CHECK-NEXT: },
// CHECK-NEXT: "valueCategory": "lvalue",
// CHECK-NEXT: "inner": [
// CHECK-NEXT: {
// CHECK-NEXT: "id": "0x{{.*}}",
// CHECK-NEXT: "kind": "MaterializeTemporaryExpr",
// CHECK-NEXT: "range": {
// CHECK-NEXT: "begin": {
// CHECK-NEXT: "col": 18,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 15
// CHECK-NEXT: },
// CHECK-NEXT: "end": {
// CHECK-NEXT: "col": 18,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 15
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "type": {
// CHECK-NEXT: "qualType": "const int"
// CHECK-NEXT: },
// CHECK-NEXT: "valueCategory": "lvalue",
// CHECK-NEXT: "extendingDecl": {
// CHECK-NEXT: "id": "0x{{.*}}",
// CHECK-NEXT: "kind": "VarDecl",
// CHECK-NEXT: "name": "i",
// CHECK-NEXT: "type": {
// CHECK-NEXT: "qualType": "const int &"
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "storageDuration": "automatic",
// CHECK-NEXT: "boundToLValueRef": true,
// CHECK-NEXT: "inner": [
// CHECK-NEXT: {
// CHECK-NEXT: "id": "0x{{.*}}",
// CHECK-NEXT: "kind": "ImplicitCastExpr",
// CHECK-NEXT: "range": {
// CHECK-NEXT: "begin": {
// CHECK-NEXT: "col": 18,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 15
// CHECK-NEXT: },
// CHECK-NEXT: "end": {
// CHECK-NEXT: "col": 18,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 15
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "type": {
// CHECK-NEXT: "qualType": "const int"
// CHECK-NEXT: },
// CHECK-NEXT: "valueCategory": "rvalue",
// CHECK-NEXT: "castKind": "FloatingToIntegral",
// CHECK-NEXT: "inner": [
// CHECK-NEXT: {
// CHECK-NEXT: "id": "0x{{.*}}",
// CHECK-NEXT: "kind": "FloatingLiteral",
// CHECK-NEXT: "range": {
// CHECK-NEXT: "begin": {
// CHECK-NEXT: "col": 18,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 15
// CHECK-NEXT: },
// CHECK-NEXT: "end": {
// CHECK-NEXT: "col": 18,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 15
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "type": {
// CHECK-NEXT: "qualType": "double"
// CHECK-NEXT: },
// CHECK-NEXT: "valueCategory": "rvalue",
// CHECK-NEXT: "value": 1
// CHECK-NEXT: }
// CHECK-NEXT: ]
// CHECK-NEXT: }
// CHECK-NEXT: ]
// CHECK-NEXT: }
// CHECK-NEXT: ]
// CHECK-NEXT: }
// CHECK: "kind": "ExprWithCleanups",
// CHECK-NEXT: "range": {
// CHECK-NEXT: "begin": {
// CHECK-NEXT: "col": 3,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 18
// CHECK-NEXT: },
// CHECK-NEXT: "end": {
// CHECK-NEXT: "col": 9,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 18
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "type": {
// CHECK-NEXT: "qualType": "void"
// CHECK-NEXT: },
// CHECK-NEXT: "valueCategory": "rvalue",
// CHECK-NEXT: "inner": [
// CHECK-NEXT: {
// CHECK-NEXT: "id": "0x{{.*}}",
// CHECK-NEXT: "kind": "CallExpr",
// CHECK-NEXT: "range": {
// CHECK-NEXT: "begin": {
// CHECK-NEXT: "col": 3,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 18
// CHECK-NEXT: },
// CHECK-NEXT: "end": {
// CHECK-NEXT: "col": 9,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 18
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "type": {
// CHECK-NEXT: "qualType": "void"
// CHECK-NEXT: },
// CHECK-NEXT: "valueCategory": "rvalue",
// CHECK-NEXT: "inner": [
// CHECK-NEXT: {
// CHECK-NEXT: "id": "0x{{.*}}",
// CHECK-NEXT: "kind": "ImplicitCastExpr",
// CHECK-NEXT: "range": {
// CHECK-NEXT: "begin": {
// CHECK-NEXT: "col": 3,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 18
// CHECK-NEXT: },
// CHECK-NEXT: "end": {
// CHECK-NEXT: "col": 3,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 18
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "type": {
// CHECK-NEXT: "qualType": "void (*)(const int &)"
// CHECK-NEXT: },
// CHECK-NEXT: "valueCategory": "rvalue",
// CHECK-NEXT: "castKind": "FunctionToPointerDecay",
// CHECK-NEXT: "inner": [
// CHECK-NEXT: {
// CHECK-NEXT: "id": "0x{{.*}}",
// CHECK-NEXT: "kind": "DeclRefExpr",
// CHECK-NEXT: "range": {
// CHECK-NEXT: "begin": {
// CHECK-NEXT: "col": 3,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 18
// CHECK-NEXT: },
// CHECK-NEXT: "end": {
// CHECK-NEXT: "col": 3,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 18
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "type": {
// CHECK-NEXT: "qualType": "void (const int &)"
// CHECK-NEXT: },
// CHECK-NEXT: "valueCategory": "lvalue",
// CHECK-NEXT: "referencedDecl": {
// CHECK-NEXT: "id": "0x{{.*}}",
// CHECK-NEXT: "kind": "FunctionDecl",
// CHECK-NEXT: "name": "func",
// CHECK-NEXT: "type": {
// CHECK-NEXT: "qualType": "void (const int &)"
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: ]
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "id": "0x{{.*}}",
// CHECK-NEXT: "kind": "MaterializeTemporaryExpr",
// CHECK-NEXT: "range": {
// CHECK-NEXT: "begin": {
// CHECK-NEXT: "col": 8,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 18
// CHECK-NEXT: },
// CHECK-NEXT: "end": {
// CHECK-NEXT: "col": 8,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 18
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "type": {
// CHECK-NEXT: "qualType": "const int"
// CHECK-NEXT: },
// CHECK-NEXT: "valueCategory": "lvalue",
// CHECK-NEXT: "storageDuration": "full expression",
// CHECK-NEXT: "boundToLValueRef": true,
// CHECK-NEXT: "inner": [
// CHECK-NEXT: {
// CHECK-NEXT: "id": "0x{{.*}}",
// CHECK-NEXT: "kind": "ImplicitCastExpr",
// CHECK-NEXT: "range": {
// CHECK-NEXT: "begin": {
// CHECK-NEXT: "col": 8,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 18
// CHECK-NEXT: },
// CHECK-NEXT: "end": {
// CHECK-NEXT: "col": 8,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 18
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "type": {
// CHECK-NEXT: "qualType": "const int"
// CHECK-NEXT: },
// CHECK-NEXT: "valueCategory": "rvalue",
// CHECK-NEXT: "castKind": "FloatingToIntegral",
// CHECK-NEXT: "inner": [
// CHECK-NEXT: {
// CHECK-NEXT: "id": "0x{{.*}}",
// CHECK-NEXT: "kind": "ImplicitCastExpr",
// CHECK-NEXT: "range": {
// CHECK-NEXT: "begin": {
// CHECK-NEXT: "col": 8,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 18
// CHECK-NEXT: },
// CHECK-NEXT: "end": {
// CHECK-NEXT: "col": 8,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 18
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "type": {
// CHECK-NEXT: "qualType": "float"
// CHECK-NEXT: },
// CHECK-NEXT: "valueCategory": "rvalue",
// 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: "col": 8,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 18
// CHECK-NEXT: },
// CHECK-NEXT: "end": {
// CHECK-NEXT: "col": 8,
// CHECK-NEXT: "file": "{{.*}}",
// CHECK-NEXT: "line": 18
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "type": {
// CHECK-NEXT: "qualType": "float"
// CHECK-NEXT: },
// CHECK-NEXT: "valueCategory": "lvalue",
// CHECK-NEXT: "referencedDecl": {
// CHECK-NEXT: "id": "0x{{.*}}",
// CHECK-NEXT: "kind": "VarDecl",
// CHECK-NEXT: "name": "f",
// CHECK-NEXT: "type": {
// CHECK-NEXT: "qualType": "float"
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: ]
// CHECK-NEXT: }
// CHECK-NEXT: ]
// CHECK-NEXT: }
// CHECK-NEXT: ]
// CHECK-NEXT: }
// CHECK-NEXT: ]
// CHECK-NEXT: }
// CHECK-NEXT: ]
// CHECK-NEXT: }