[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
Wed Apr 13 03:03:22 PDT 2022


tblah created this revision.
tblah added a reviewer: rsmith.
Herald added a project: All.
tblah requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

NamedDecl::getIdentifier can return a nullptr when DeclarationName::isIdentifier is false, which leads to a null pointer dereference when TypePrinter::printTemplateId calls ->getName().

NamedDecl::getName does the same thing in the successful case and returns an empty string in the failure case.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123667

Files:
  clang/lib/AST/TypePrinter.cpp


Index: clang/lib/AST/TypePrinter.cpp
===================================================================
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -1466,8 +1466,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.422449.patch
Type: text/x-patch
Size: 455 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220413/75d55ac0/attachment-0001.bin>


More information about the cfe-commits mailing list