Author: Jonas Hahnfeld
Date: 2026-01-15T08:54:51+01:00
New Revision: c5407e0fbd9ddfa67f5c326fb35842121c0a055d

URL: 
https://github.com/llvm/llvm-project/commit/c5407e0fbd9ddfa67f5c326fb35842121c0a055d
DIFF: 
https://github.com/llvm/llvm-project/commit/c5407e0fbd9ddfa67f5c326fb35842121c0a055d.diff

LOG: [Serialization] Hash inner template arguments

The code is applied from ODRHash::AddDecl with the reasoning given
in the comment, to reduce collisions. This was particularly visible
with STL types templated on std::pair where its template arguments
were not taken into account.

Reviewed as part of https://github.com/llvm/llvm-project/pull/133057

Added: 
    

Modified: 
    clang/lib/Serialization/TemplateArgumentHasher.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Serialization/TemplateArgumentHasher.cpp 
b/clang/lib/Serialization/TemplateArgumentHasher.cpp
index 353e8a2daa925..da2c70ca17b79 100644
--- a/clang/lib/Serialization/TemplateArgumentHasher.cpp
+++ b/clang/lib/Serialization/TemplateArgumentHasher.cpp
@@ -202,6 +202,21 @@ void TemplateArgumentHasher::AddDecl(const Decl *D) {
   }
 
   AddDeclarationName(ND->getDeclName());
+
+  // If this was a specialization we should take into account its template
+  // arguments. This helps to reduce collisions coming when visiting template
+  // specialization types (eg. when processing type template arguments).
+  ArrayRef<TemplateArgument> Args;
+  if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(D))
+    Args = CTSD->getTemplateArgs().asArray();
+  else if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(D))
+    Args = VTSD->getTemplateArgs().asArray();
+  else if (auto *FD = dyn_cast<FunctionDecl>(D))
+    if (FD->getTemplateSpecializationArgs())
+      Args = FD->getTemplateSpecializationArgs()->asArray();
+
+  for (auto &TA : Args)
+    AddTemplateArgument(TA);
 }
 
 void TemplateArgumentHasher::AddQualType(QualType T) {


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to