[clang] 493d805 - [AST] Dump containsErrors bit for the Type.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 18 23:46:01 PDT 2020
Author: Haojian Wu
Date: 2020-06-19T08:45:46+02:00
New Revision: 493d8059f3991e35c9d4dd1cb6cbeade426dc0ea
URL: https://github.com/llvm/llvm-project/commit/493d8059f3991e35c9d4dd1cb6cbeade426dc0ea
DIFF: https://github.com/llvm/llvm-project/commit/493d8059f3991e35c9d4dd1cb6cbeade426dc0ea.diff
LOG: [AST] Dump containsErrors bit for the Type.
Reviewers: sammccall
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D81912
Added:
clang/test/AST/ast-dump-types-errors-json.cpp
clang/test/AST/ast-dump-types-errors.cpp
Modified:
clang/lib/AST/JSONNodeDumper.cpp
clang/lib/AST/TextNodeDumper.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/JSONNodeDumper.cpp b/clang/lib/AST/JSONNodeDumper.cpp
index f3c5cfaa011e..c9a84a2b7d57 100644
--- a/clang/lib/AST/JSONNodeDumper.cpp
+++ b/clang/lib/AST/JSONNodeDumper.cpp
@@ -74,6 +74,7 @@ void JSONNodeDumper::Visit(const Type *T) {
JOS.attribute("kind", (llvm::Twine(T->getTypeClassName()) + "Type").str());
JOS.attribute("type", createQualType(QualType(T, 0), /*Desugar*/ false));
+ attributeOnlyIfTrue("containsErrors", T->containsErrors());
attributeOnlyIfTrue("isDependent", T->isDependentType());
attributeOnlyIfTrue("isInstantiationDependent",
T->isInstantiationDependentType());
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index a365431cd602..0d49c443e03e 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -202,6 +202,11 @@ void TextNodeDumper::Visit(const Type *T) {
if (SingleStepDesugar != QualType(T, 0))
OS << " sugar";
+ if (T->containsErrors()) {
+ ColorScope Color(OS, ShowColors, ErrorsColor);
+ OS << " contains-errors";
+ }
+
if (T->isDependentType())
OS << " dependent";
else if (T->isInstantiationDependentType())
diff --git a/clang/test/AST/ast-dump-types-errors-json.cpp b/clang/test/AST/ast-dump-types-errors-json.cpp
new file mode 100644
index 000000000000..5504615630b4
--- /dev/null
+++ b/clang/test/AST/ast-dump-types-errors-json.cpp
@@ -0,0 +1,141 @@
+// RUN: not %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -ast-dump=json -ast-dump-filter Test %s | FileCheck %s
+
+using TestContainsErrors = int[sizeof(undef())];
+
+
+// CHECK: "kind": "TypeAliasDecl",
+// CHECK-NEXT: "loc": {
+// CHECK-NEXT: "offset": 130,
+// CHECK-NEXT: "file": "{{.*}}",
+// CHECK-NEXT: "line": 3,
+// CHECK-NEXT: "col": 7,
+// CHECK-NEXT: "tokLen": 18
+// CHECK-NEXT: },
+// CHECK-NEXT: "range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT: "offset": 124,
+// CHECK-NEXT: "col": 1,
+// CHECK-NEXT: "tokLen": 5
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT: "offset": 170,
+// CHECK-NEXT: "col": 47,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: }
+// CHECK-NEXT: },
+// CHECK-NEXT: "name": "TestContainsErrors",
+// CHECK-NEXT: "type": {
+// CHECK-NEXT: "qualType": "int [sizeof (<recovery-expr>(undef))]"
+// CHECK-NEXT: },
+// CHECK-NEXT: "inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "DependentSizedArrayType",
+// CHECK-NEXT: "type": {
+// CHECK-NEXT: "qualType": "int [sizeof (<recovery-expr>(undef))]"
+// CHECK-NEXT: },
+// CHECK-NEXT: "containsErrors": true,
+// CHECK-NEXT: "isDependent": true,
+// CHECK-NEXT: "isInstantiationDependent": true,
+// CHECK-NEXT: "inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "BuiltinType",
+// CHECK-NEXT: "type": {
+// CHECK-NEXT: "qualType": "int"
+// CHECK-NEXT: }
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "UnaryExprOrTypeTraitExpr",
+// CHECK-NEXT: "range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT: "offset": 155,
+// CHECK-NEXT: "col": 32,
+// CHECK-NEXT: "tokLen": 6
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT: "offset": 169,
+// CHECK-NEXT: "col": 46,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: }
+// CHECK-NEXT: },
+// CHECK-NEXT: "type": {
+// CHECK-NEXT: "qualType": "unsigned long"
+// CHECK-NEXT: },
+// CHECK-NEXT: "valueCategory": "rvalue",
+// CHECK-NEXT: "name": "sizeof",
+// CHECK-NEXT: "inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "ParenExpr",
+// CHECK-NEXT: "range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT: "offset": 161,
+// CHECK-NEXT: "col": 38,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT: "offset": 169,
+// CHECK-NEXT: "col": 46,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: }
+// CHECK-NEXT: },
+// CHECK-NEXT: "type": {
+// CHECK-NEXT: "qualType": "<dependent type>"
+// CHECK-NEXT: },
+// CHECK-NEXT: "valueCategory": "lvalue",
+// CHECK-NEXT: "inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "RecoveryExpr",
+// CHECK-NEXT: "range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT: "offset": 162,
+// CHECK-NEXT: "col": 39,
+// CHECK-NEXT: "tokLen": 5
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT: "offset": 168,
+// CHECK-NEXT: "col": 45,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: }
+// CHECK-NEXT: },
+// CHECK-NEXT: "type": {
+// CHECK-NEXT: "qualType": "<dependent type>"
+// CHECK-NEXT: },
+// CHECK-NEXT: "valueCategory": "lvalue",
+// CHECK-NEXT: "inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "UnresolvedLookupExpr",
+// CHECK-NEXT: "range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT: "offset": 162,
+// CHECK-NEXT: "col": 39,
+// CHECK-NEXT: "tokLen": 5
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT: "offset": 162,
+// CHECK-NEXT: "col": 39,
+// CHECK-NEXT: "tokLen": 5
+// CHECK-NEXT: }
+// CHECK-NEXT: },
+// CHECK-NEXT: "type": {
+// CHECK-NEXT: "qualType": "<overloaded function type>"
+// CHECK-NEXT: },
+// CHECK-NEXT: "valueCategory": "lvalue",
+// CHECK-NEXT: "usesADL": true,
+// CHECK-NEXT: "name": "undef",
+// CHECK-NEXT: "lookups": []
+// CHECK-NEXT: }
+// CHECK-NEXT: ]
+// CHECK-NEXT: }
+// CHECK-NEXT: ]
+// CHECK-NEXT: }
+// CHECK-NEXT: ]
+// CHECK-NEXT: }
+// CHECK-NEXT: ]
+// CHECK-NEXT: }
+// CHECK-NEXT: ]
+// CHECK-NEXT: }
diff --git a/clang/test/AST/ast-dump-types-errors.cpp b/clang/test/AST/ast-dump-types-errors.cpp
new file mode 100644
index 000000000000..b623fd049399
--- /dev/null
+++ b/clang/test/AST/ast-dump-types-errors.cpp
@@ -0,0 +1,6 @@
+// RUN: not %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -ast-dump %s | FileCheck %s
+
+void test() {
+ using ContainsErrors = int[sizeof(undef())];
+ // CHECK: DependentSizedArrayType {{.*}} contains-errors dependent
+}
More information about the cfe-commits
mailing list