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();
 


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();
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to