[PATCH] D123667: [clang][AST] Fix crash getting name of a template decl

Tom Eccles via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 14 10:25:07 PDT 2022


tblah updated this revision to Diff 422906.
tblah added a comment.

Added a unit test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123667/new/

https://reviews.llvm.org/D123667

Files:
  clang/lib/AST/TypePrinter.cpp
  clang/unittests/AST/TypePrinterTest.cpp


Index: clang/unittests/AST/TypePrinterTest.cpp
===================================================================
--- clang/unittests/AST/TypePrinterTest.cpp
+++ clang/unittests/AST/TypePrinterTest.cpp
@@ -64,6 +64,22 @@
       [](PrintingPolicy &Policy) { Policy.FullyQualifiedName = true; }));
 }
 
+TEST(TypePrinter, TemplateId2) {
+  std::string Code = R"cpp(
+      template <template <typename ...> class TemplatedType>
+      void func(TemplatedType<int> Param);
+    )cpp";
+  auto Matcher = parmVarDecl(hasType(qualType().bind("id")));
+
+  // regression test ensuring we do not segfault getting the qualtype as a
+  // string
+  ASSERT_TRUE(PrintedTypeMatches(Code, {}, Matcher, "<int>",
+                                 [](PrintingPolicy &Policy) {
+                                   Policy.FullyQualifiedName = true;
+                                   Policy.PrintCanonicalTypes = true;
+                                 }));
+}
+
 TEST(TypePrinter, ParamsUglified) {
   llvm::StringLiteral Code = R"cpp(
     template <typename _Tp, template <typename> class __f>
Index: clang/lib/AST/TypePrinter.cpp
===================================================================
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -1467,8 +1467,7 @@
     if (!Policy.SuppressScope)
       AppendScope(TD->getDeclContext(), OS, TD->getDeclName());
 
-    IdentifierInfo *II = TD->getIdentifier();
-    OS << II->getName();
+    OS << TD->getName();
   } else {
     T->getTemplateName().print(OS, Policy);
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123667.422906.patch
Type: text/x-patch
Size: 1536 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220414/ff51f537/attachment.bin>


More information about the cfe-commits mailing list