[clang] 7fb606e - [Clang] Fix a crash when using ast-dump=json (#70224)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 13 13:39:45 PST 2023
Author: elizabethandrews
Date: 2023-11-13T16:39:40-05:00
New Revision: 7fb606e9feb9a4f23acf96ccf73ae676ca883828
URL: https://github.com/llvm/llvm-project/commit/7fb606e9feb9a4f23acf96ccf73ae676ca883828
DIFF: https://github.com/llvm/llvm-project/commit/7fb606e9feb9a4f23acf96ccf73ae676ca883828.diff
LOG: [Clang] Fix a crash when using ast-dump=json (#70224)
CXXDeductionGuideDecl inherits from FunctionDecl. For FunctionDecls,
the JSONVisitor includes a call to visit NamedDecl in order to provide
mangled names in the dump. This did not correctly exclude
CXXDeductionGuideDecl, which resulted in an assert being hit.
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/AST/JSONNodeDumper.cpp
clang/test/AST/ast-dump-template-decls-json.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 66f82de69099533..ed1a978b5382d71 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -726,6 +726,8 @@ Miscellaneous Clang Crashes Fixed
(`#68001 <https://github.com/llvm/llvm-project/pull/68001>`_)
- Fixed a crash in C when redefined struct is another nested redefinition.
`Issue 41302 <https://github.com/llvm/llvm-project/issues/41302>`_
+- Fixed a crash when ``-ast-dump=json`` was used for code using class
+ template deduction guides.
Target Specific Changes
-----------------------
diff --git a/clang/lib/AST/JSONNodeDumper.cpp b/clang/lib/AST/JSONNodeDumper.cpp
index ace5178bf625828..637d06cee78c852 100644
--- a/clang/lib/AST/JSONNodeDumper.cpp
+++ b/clang/lib/AST/JSONNodeDumper.cpp
@@ -823,6 +823,10 @@ void JSONNodeDumper::VisitNamedDecl(const NamedDecl *ND) {
if (VD && VD->hasLocalStorage())
return;
+ // Do not mangle template deduction guides.
+ if (isa<CXXDeductionGuideDecl>(ND))
+ return;
+
std::string MangledName = ASTNameGen.getName(ND);
if (!MangledName.empty())
JOS.attribute("mangledName", MangledName);
diff --git a/clang/test/AST/ast-dump-template-decls-json.cpp b/clang/test/AST/ast-dump-template-decls-json.cpp
index 00a656cd059178d..70f1d3b55f3ee98 100644
--- a/clang/test/AST/ast-dump-template-decls-json.cpp
+++ b/clang/test/AST/ast-dump-template-decls-json.cpp
@@ -58,6 +58,10 @@ void V<Ty>::f() {}
template <template <typename> class = R>
void i();
+template <int A> class W{
+};
+W(int)->W<1>;
+
// NOTE: CHECK lines have been autogenerated by gen_ast_dump_json_test.py
@@ -2702,6 +2706,427 @@ void i();
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: ]
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "ClassTemplateDecl",
+// CHECK-NEXT: "loc": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "line": 61,
+// CHECK-NEXT: "col": 24,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: },
+// CHECK-NEXT: "range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 1,
+// CHECK-NEXT: "tokLen": 8
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "line": 62,
+// CHECK-NEXT: "col": 1,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: }
+// CHECK-NEXT: },
+// CHECK-NEXT: "name": "W",
+// CHECK-NEXT: "inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "NonTypeTemplateParmDecl",
+// CHECK-NEXT: "loc": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "line": 61,
+// CHECK-NEXT: "col": 15,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: },
+// CHECK-NEXT: "range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 11,
+// CHECK-NEXT: "tokLen": 3
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 15,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: }
+// CHECK-NEXT: },
+// CHECK-NEXT: "name": "A",
+// CHECK-NEXT: "type": {
+// CHECK-NEXT: "qualType": "int"
+// CHECK-NEXT: },
+// CHECK-NEXT: "depth": 0,
+// CHECK-NEXT: "index": 0
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "CXXRecordDecl",
+// CHECK-NEXT: "loc": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 24,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: },
+// CHECK-NEXT: "range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 18,
+// CHECK-NEXT: "tokLen": 5
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "line": 62,
+// CHECK-NEXT: "col": 1,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: }
+// CHECK-NEXT: },
+// CHECK-NEXT: "name": "W",
+// CHECK-NEXT: "tagUsed": "class",
+// CHECK-NEXT: "completeDefinition": true,
+// CHECK-NEXT: "definitionData": {
+// CHECK-NEXT: "canConstDefaultInit": true,
+// CHECK-NEXT: "copyAssign": {
+// CHECK-NEXT: "hasConstParam": true,
+// CHECK-NEXT: "implicitHasConstParam": true,
+// CHECK-NEXT: "needsImplicit": true,
+// CHECK-NEXT: "simple": true,
+// CHECK-NEXT: "trivial": true
+// CHECK-NEXT: },
+// CHECK-NEXT: "copyCtor": {
+// CHECK-NEXT: "hasConstParam": true,
+// CHECK-NEXT: "implicitHasConstParam": true,
+// CHECK-NEXT: "needsImplicit": true,
+// CHECK-NEXT: "simple": true,
+// CHECK-NEXT: "trivial": true
+// CHECK-NEXT: },
+// CHECK-NEXT: "defaultCtor": {
+// CHECK-NEXT: "defaultedIsConstexpr": true,
+// CHECK-NEXT: "exists": true,
+// CHECK-NEXT: "isConstexpr": true,
+// CHECK-NEXT: "needsImplicit": true,
+// CHECK-NEXT: "trivial": true
+// CHECK-NEXT: },
+// CHECK-NEXT: "dtor": {
+// CHECK-NEXT: "irrelevant": true,
+// CHECK-NEXT: "needsImplicit": true,
+// CHECK-NEXT: "simple": true,
+// CHECK-NEXT: "trivial": true
+// CHECK-NEXT: },
+// CHECK-NEXT: "hasConstexprNonCopyMoveConstructor": true,
+// CHECK-NEXT: "isAggregate": true,
+// CHECK-NEXT: "isEmpty": true,
+// CHECK-NEXT: "isLiteral": true,
+// CHECK-NEXT: "isPOD": true,
+// CHECK-NEXT: "isStandardLayout": true,
+// CHECK-NEXT: "isTrivial": true,
+// CHECK-NEXT: "isTriviallyCopyable": true,
+// CHECK-NEXT: "moveAssign": {
+// CHECK-NEXT: "exists": true,
+// CHECK-NEXT: "needsImplicit": true,
+// CHECK-NEXT: "simple": true,
+// CHECK-NEXT: "trivial": true
+// CHECK-NEXT: },
+// CHECK-NEXT: "moveCtor": {
+// CHECK-NEXT: "exists": true,
+// CHECK-NEXT: "needsImplicit": true,
+// CHECK-NEXT: "simple": true,
+// CHECK-NEXT: "trivial": true
+// CHECK-NEXT: }
+// CHECK-NEXT: },
+// CHECK-NEXT: "inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "CXXRecordDecl",
+// CHECK-NEXT: "loc": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "line": 61,
+// CHECK-NEXT: "col": 24,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: },
+// CHECK-NEXT: "range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 18,
+// CHECK-NEXT: "tokLen": 5
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 24,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: }
+// CHECK-NEXT: },
+// CHECK-NEXT: "isImplicit": true,
+// CHECK-NEXT: "name": "W",
+// CHECK-NEXT: "tagUsed": "class"
+// CHECK-NEXT: }
+// CHECK-NEXT: ]
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "ClassTemplateSpecializationDecl",
+// CHECK-NEXT: "loc": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 24,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: },
+// CHECK-NEXT: "range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 1,
+// CHECK-NEXT: "tokLen": 8
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "line": 62,
+// CHECK-NEXT: "col": 1,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: }
+// CHECK-NEXT: },
+// CHECK-NEXT: "name": "W",
+// CHECK-NEXT: "tagUsed": "class",
+// CHECK-NEXT: "inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT: "kind": "TemplateArgument",
+// CHECK-NEXT: "value": 1
+// CHECK-NEXT: }
+// CHECK-NEXT: ]
+// CHECK-NEXT: }
+// CHECK-NEXT: ]
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "FunctionTemplateDecl",
+// CHECK-NEXT: "loc": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "line": 61,
+// CHECK-NEXT: "col": 24,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: },
+// CHECK-NEXT: "range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 1,
+// CHECK-NEXT: "tokLen": 8
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 24,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: }
+// CHECK-NEXT: },
+// CHECK-NEXT: "isImplicit": true,
+// CHECK-NEXT: "name": "<deduction guide for W>",
+// CHECK-NEXT: "inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "NonTypeTemplateParmDecl",
+// CHECK-NEXT: "loc": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 15,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: },
+// CHECK-NEXT: "range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 11,
+// CHECK-NEXT: "tokLen": 3
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 15,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: }
+// CHECK-NEXT: },
+// CHECK-NEXT: "name": "A",
+// CHECK-NEXT: "type": {
+// CHECK-NEXT: "qualType": "int"
+// CHECK-NEXT: },
+// CHECK-NEXT: "depth": 0,
+// CHECK-NEXT: "index": 0
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "CXXDeductionGuideDecl",
+// CHECK-NEXT: "loc": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 24,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: },
+// CHECK-NEXT: "range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 24,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 24,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: }
+// CHECK-NEXT: },
+// CHECK-NEXT: "isImplicit": true,
+// CHECK-NEXT: "name": "<deduction guide for W>",
+// CHECK-NEXT: "type": {
+// CHECK-NEXT: "qualType": "auto () -> W<A>"
+// CHECK-NEXT: }
+// CHECK-NEXT: }
+// CHECK-NEXT: ]
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "FunctionTemplateDecl",
+// CHECK-NEXT: "loc": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 24,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: },
+// CHECK-NEXT: "range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 1,
+// CHECK-NEXT: "tokLen": 8
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 24,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: }
+// CHECK-NEXT: },
+// CHECK-NEXT: "isImplicit": true,
+// CHECK-NEXT: "name": "<deduction guide for W>",
+// CHECK-NEXT: "inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "NonTypeTemplateParmDecl",
+// CHECK-NEXT: "loc": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 15,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: },
+// CHECK-NEXT: "range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 11,
+// CHECK-NEXT: "tokLen": 3
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 15,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: }
+// CHECK-NEXT: },
+// CHECK-NEXT: "name": "A",
+// CHECK-NEXT: "type": {
+// CHECK-NEXT: "qualType": "int"
+// CHECK-NEXT: },
+// CHECK-NEXT: "depth": 0,
+// CHECK-NEXT: "index": 0
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "CXXDeductionGuideDecl",
+// CHECK-NEXT: "loc": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 24,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: },
+// CHECK-NEXT: "range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 24,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 24,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: }
+// CHECK-NEXT: },
+// CHECK-NEXT: "isImplicit": true,
+// CHECK-NEXT: "name": "<deduction guide for W>",
+// CHECK-NEXT: "type": {
+// CHECK-NEXT: "qualType": "auto (W<A>) -> W<A>"
+// CHECK-NEXT: },
+// CHECK-NEXT: "inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "ParmVarDecl",
+// CHECK-NEXT: "loc": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 24,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: },
+// CHECK-NEXT: "range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 24,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 24,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: }
+// CHECK-NEXT: },
+// CHECK-NEXT: "type": {
+// CHECK-NEXT: "qualType": "W<A>"
+// CHECK-NEXT: }
+// CHECK-NEXT: }
+// CHECK-NEXT: ]
+// CHECK-NEXT: }
+// CHECK-NEXT: ]
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "CXXDeductionGuideDecl",
+// CHECK-NEXT: "loc": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "line": 63,
+// CHECK-NEXT: "col": 1,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: },
+// CHECK-NEXT: "range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 1,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 12,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: }
+// CHECK-NEXT: },
+// CHECK-NEXT: "name": "<deduction guide for W>",
+// CHECK-NEXT: "type": {
+// CHECK-NEXT: "qualType": "auto (int) -> W<1>"
+// CHECK-NEXT: },
+// CHECK-NEXT: "inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "ParmVarDecl",
+// CHECK-NEXT: "loc": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 6,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT: },
+// CHECK-NEXT: "range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 3,
+// CHECK-NEXT: "tokLen": 3
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "col": 3,
+// CHECK-NEXT: "tokLen": 3
+// CHECK-NEXT: }
+// CHECK-NEXT: },
+// CHECK-NEXT: "type": {
+// CHECK-NEXT: "qualType": "int"
+// CHECK-NEXT: }
+// CHECK-NEXT: }
+// CHECK-NEXT: ]
// CHECK-NEXT: }
// CHECK-NEXT: ]
// CHECK-NEXT: }
More information about the cfe-commits
mailing list