Avoid crash when dumping NULL Type as JSON.
authorAaron Ballman <aaron@aaronballman.com>
Thu, 29 Aug 2019 20:00:40 +0000 (20:00 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Thu, 29 Aug 2019 20:00:40 +0000 (20:00 +0000)
Patch by Bert Belder.

llvm-svn: 370401

clang/lib/AST/JSONNodeDumper.cpp
clang/test/AST/ast-dump-types-json.cpp
clang/test/AST/gen_ast_dump_json_test.py

index b0253c1..68f5b29 100644 (file)
@@ -66,6 +66,10 @@ void JSONNodeDumper::Visit(const Stmt *S) {
 
 void JSONNodeDumper::Visit(const Type *T) {
   JOS.attribute("id", createPointerRepresentation(T));
+
+  if (!T)
+    return;
+
   JOS.attribute("kind", (llvm::Twine(T->getTypeClassName()) + "Type").str());
   JOS.attribute("type", createQualType(QualType(T, 0), /*Desugar*/ false));
   attributeOnlyIfTrue("isDependent", T->isDependentType());
index 8b9bdd5..d25aea8 100644 (file)
@@ -20,6 +20,11 @@ typedef int T::*TestMemberDataPointerType;
 
 typedef int TestQualTypePrinting(const char* c);
 
+typedef int TestUsingShadowDeclType;
+namespace TestNamespaceWithUsingShadowType {
+using ::TestUsingShadowDeclType;
+}
+
 // NOTE: CHECK lines have been autogenerated by gen_ast_dump_json_test.py
 
 
@@ -422,3 +427,75 @@ typedef int TestQualTypePrinting(const char* c);
 // CHECK-NEXT:   }
 // CHECK-NEXT:  ]
 // CHECK-NEXT: }
+
+// CHECK:  "kind": "NamespaceDecl",
+// CHECK-NEXT:  "loc": {
+// CHECK-NEXT:   "file": "{{.*}}",
+// CHECK-NEXT:   "line": 24,
+// CHECK-NEXT:   "col": 11,
+// CHECK-NEXT:   "tokLen": 32
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "range": {
+// CHECK-NEXT:   "begin": {
+// CHECK-NEXT:    "col": 1,
+// CHECK-NEXT:    "tokLen": 9
+// CHECK-NEXT:   },
+// CHECK-NEXT:   "end": {
+// CHECK-NEXT:    "line": 26,
+// CHECK-NEXT:    "col": 1,
+// CHECK-NEXT:    "tokLen": 1
+// CHECK-NEXT:   }
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "name": "TestNamespaceWithUsingShadowType",
+// CHECK-NEXT:  "inner": [
+// CHECK-NEXT:   {
+// CHECK-NEXT:    "id": "0x{{.*}}",
+// CHECK-NEXT:    "kind": "UsingDecl",
+// CHECK-NEXT:    "loc": {
+// CHECK-NEXT:     "line": 25,
+// CHECK-NEXT:     "col": 9,
+// CHECK-NEXT:     "tokLen": 23
+// CHECK-NEXT:    },
+// CHECK-NEXT:    "range": {
+// CHECK-NEXT:     "begin": {
+// CHECK-NEXT:      "col": 1,
+// CHECK-NEXT:      "tokLen": 5
+// CHECK-NEXT:     },
+// CHECK-NEXT:     "end": {
+// CHECK-NEXT:      "col": 9,
+// CHECK-NEXT:      "tokLen": 23
+// CHECK-NEXT:     }
+// CHECK-NEXT:    },
+// CHECK-NEXT:    "name": "::TestUsingShadowDeclType"
+// CHECK-NEXT:   },
+// CHECK-NEXT:   {
+// CHECK-NEXT:    "id": "0x{{.*}}",
+// CHECK-NEXT:    "kind": "UsingShadowDecl",
+// CHECK-NEXT:    "loc": {
+// CHECK-NEXT:     "col": 9,
+// CHECK-NEXT:     "tokLen": 23
+// CHECK-NEXT:    },
+// CHECK-NEXT:    "range": {
+// CHECK-NEXT:     "begin": {
+// CHECK-NEXT:      "col": 9,
+// CHECK-NEXT:      "tokLen": 23
+// CHECK-NEXT:     },
+// CHECK-NEXT:     "end": {
+// CHECK-NEXT:      "col": 9,
+// CHECK-NEXT:      "tokLen": 23
+// CHECK-NEXT:     }
+// CHECK-NEXT:    },
+// CHECK-NEXT:    "isImplicit": true,
+// CHECK-NEXT:    "target": {
+// CHECK-NEXT:     "id": "0x{{.*}}",
+// CHECK-NEXT:     "kind": "TypedefDecl",
+// CHECK-NEXT:     "name": "TestUsingShadowDeclType"
+// CHECK-NEXT:    },
+// CHECK-NEXT:    "inner": [
+// CHECK-NEXT:     {
+// CHECK-NEXT:      "id": "0x0"
+// CHECK-NEXT:     }
+// CHECK-NEXT:    ]
+// CHECK-NEXT:   }
+// CHECK-NEXT:  ]
+// CHECK-NEXT: }
index 975039e..f1c9801 100644 (file)
@@ -20,7 +20,7 @@ def normalize(dict_var):
                     normalize(e)
         elif type(v) is unicode:
             st = v.encode('utf-8')
-            if re.match(r"0x[0-9A-Fa-f]+", v):
+            if v != "0x0" and re.match(r"0x[0-9A-Fa-f]+", v):
                 dict_var[k] = u'0x{{.*}}'
             elif os.path.isfile(v):
                 dict_var[k] = u'{{.*}}'