https://github.com/elizabethandrews updated 
https://github.com/llvm/llvm-project/pull/70224

>From 4ea6d62dab962eba6e52a9fdf7e61b6aac0714fa Mon Sep 17 00:00:00 2001
From: Elizabeth Andrews <elizabeth.andr...@intel.com>
Date: Mon, 30 Oct 2023 13:07:48 -0700
Subject: [PATCH] [Clang] Fix a crash when using ast-dump=json

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.
---
 clang/docs/ReleaseNotes.rst                   |   2 +
 clang/lib/AST/JSONNodeDumper.cpp              |   4 +
 .../test/AST/ast-dump-template-decls-json.cpp | 425 ++++++++++++++++++
 3 files changed, 431 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 66f82de69099533c..ed1a978b5382d719 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 ace5178bf6258289..637d06cee78c8525 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 00a656cd059178dd..70f1d3b55f3ee988 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: }

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to