[PATCH] D144622: [clang[[ASTImporter] Import TemplateName correctly

Balázs Kéri via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 23 00:28:06 PST 2023


balazske created this revision.
Herald added subscribers: steakhal, martong, gamesh411, Szelethus, dkrupp.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: All.
balazske requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is a fix for a problem when multiple template
specializations are created by ASTImporter, with similar template arguments.
I think with same arguments ony a single specialization should exist, the
problem needs more investigation, but the TemplateName objects
(where a pointer to the specialization is used as identifier and key in a map)
should have all the same pointer to the same specialization, otherwise they
may compare as different even if the template that they refer to is the same.
In the wrong case some redundant AST nodes may be created by ASTImporter.
When these appear in type alias declaration the assertion
`assert(hasSameType(Decl->getUnderlyingType(), Underlying))` (ASTContext.cpp:4786)
may fail.

This is a work-in-progress fix, tests are not added yet.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144622

Files:
  clang/lib/AST/ASTImporter.cpp


Index: clang/lib/AST/ASTImporter.cpp
===================================================================
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -9376,7 +9376,7 @@
   switch (From.getKind()) {
   case TemplateName::Template:
     if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
-      return TemplateName(cast<TemplateDecl>(*ToTemplateOrErr));
+      return TemplateName(cast<TemplateDecl>((*ToTemplateOrErr)->getCanonicalDecl()));
     else
       return ToTemplateOrErr.takeError();
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144622.499756.patch
Type: text/x-patch
Size: 539 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230223/2ce64bd9/attachment.bin>


More information about the cfe-commits mailing list