[cfe-commits] r113481 - in /cfe/trunk: include/clang/AST/DeclTemplate.h lib/AST/Decl.cpp lib/Serialization/ASTReaderDecl.cpp lib/Serialization/ASTWriterDecl.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Thu Sep 9 04:28:23 PDT 2010


Author: akirtzidis
Date: Thu Sep  9 06:28:23 2010
New Revision: 113481

URL: http://llvm.org/viewvc/llvm-project?rev=113481&view=rev
Log:
Fix C++ PCH issue.

Another beating by boost in this test case: http://llvm.org/PR8117
A function specialization wasn't properly initialized if it wasn't canonical.

I wish there was a nice little test case but this was boost.

Modified:
    cfe/trunk/include/clang/AST/DeclTemplate.h
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
    cfe/trunk/lib/Serialization/ASTWriterDecl.cpp

Modified: cfe/trunk/include/clang/AST/DeclTemplate.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclTemplate.h?rev=113481&r1=113480&r2=113481&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclTemplate.h (original)
+++ cfe/trunk/include/clang/AST/DeclTemplate.h Thu Sep  9 06:28:23 2010
@@ -292,7 +292,31 @@
 /// which is a FunctionDecl that has been explicitly specialization or
 /// instantiated from a function template.
 class FunctionTemplateSpecializationInfo : public llvm::FoldingSetNode {
+  FunctionTemplateSpecializationInfo(FunctionDecl *FD,
+                                     FunctionTemplateDecl *Template,
+                                     TemplateSpecializationKind TSK,
+                                     const TemplateArgumentList *TemplateArgs,
+                          const TemplateArgumentListInfo *TemplateArgsAsWritten,
+                                     SourceLocation POI)
+  : Function(FD),
+    Template(Template, TSK - 1),
+    TemplateArguments(TemplateArgs),
+    TemplateArgumentsAsWritten(TemplateArgsAsWritten),
+    PointOfInstantiation(POI) { }
+
 public:
+  static FunctionTemplateSpecializationInfo *
+  Create(ASTContext &C, FunctionDecl *FD, FunctionTemplateDecl *Template,
+         TemplateSpecializationKind TSK,
+         const TemplateArgumentList *TemplateArgs,
+         const TemplateArgumentListInfo *TemplateArgsAsWritten,
+         SourceLocation POI) {
+    return new (C) FunctionTemplateSpecializationInfo(FD, Template, TSK,
+                                                      TemplateArgs,
+                                                      TemplateArgsAsWritten,
+                                                      POI);
+  }
+
   /// \brief The function template specialization that this structure
   /// describes.
   FunctionDecl *Function;

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=113481&r1=113480&r2=113481&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Thu Sep  9 06:28:23 2010
@@ -1376,14 +1376,10 @@
   FunctionTemplateSpecializationInfo *Info
     = TemplateOrSpecialization.dyn_cast<FunctionTemplateSpecializationInfo*>();
   if (!Info)
-    Info = new (C) FunctionTemplateSpecializationInfo;
-
-  Info->Function = this;
-  Info->Template.setPointer(Template);
-  Info->Template.setInt(TSK - 1);
-  Info->TemplateArguments = TemplateArgs;
-  Info->TemplateArgumentsAsWritten = TemplateArgsAsWritten;
-  Info->PointOfInstantiation = PointOfInstantiation;
+    Info = FunctionTemplateSpecializationInfo::Create(C, this, Template, TSK,
+                                                      TemplateArgs,
+                                                      TemplateArgsAsWritten,
+                                                      PointOfInstantiation);
   TemplateOrSpecialization = Info;
 
   // Insert this function template specialization into the set of known

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=113481&r1=113480&r2=113481&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Thu Sep  9 06:28:23 2010
@@ -280,25 +280,32 @@
     
     SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
 
-    if (FD->isCanonicalDecl()) { // if canonical add to template's set.
-      ASTContext &C = *Reader.getContext();
-      TemplateArgumentList *TemplArgList
-        = new (C) TemplateArgumentList(C, TemplArgs.data(), TemplArgs.size());
-      TemplateArgumentListInfo *TemplArgsInfo
-        = new (C) TemplateArgumentListInfo(LAngleLoc, RAngleLoc);
-      for (unsigned i=0, e = TemplArgLocs.size(); i != e; ++i)
-        TemplArgsInfo->addArgument(TemplArgLocs[i]);
+    ASTContext &C = *Reader.getContext();
+    TemplateArgumentList *TemplArgList
+      = new (C) TemplateArgumentList(C, TemplArgs.data(), TemplArgs.size());
+    TemplateArgumentListInfo *TemplArgsInfo
+      = new (C) TemplateArgumentListInfo(LAngleLoc, RAngleLoc);
+    for (unsigned i=0, e = TemplArgLocs.size(); i != e; ++i)
+      TemplArgsInfo->addArgument(TemplArgLocs[i]);
+    FunctionTemplateSpecializationInfo *FTInfo
+        = FunctionTemplateSpecializationInfo::Create(C, FD, Template, TSK,
+                                                     TemplArgList,
+                                                     TemplArgsInfo, POI);
+    FD->TemplateOrSpecialization = FTInfo;
 
+    if (FD->isCanonicalDecl()) { // if canonical add to template's set.
+      // Get the InsertPos by FindNodeOrInsertPos() instead of calling
+      // InsertNode(FTInfo) directly to avoid the getASTContext() call in
+      // FunctionTemplateSpecializationInfo's Profile().
+      // We avoid getASTContext because a decl in the parent hierarchy may
+      // be initializing.
       llvm::FoldingSetNodeID ID;
       FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs.data(),
                                                   TemplArgs.size(), C);
       void *InsertPos = 0;
-      FunctionTemplateSpecializationInfo *PrevFTInfo =
-          Template->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
-      (void)PrevFTInfo;
-      assert(!PrevFTInfo && "Another specialization already inserted!");
-      FD->setFunctionTemplateSpecialization(C, Template, TemplArgList, InsertPos,
-                                            TSK, TemplArgsInfo, POI);
+      Template->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
+      assert(InsertPos && "Another specialization already inserted!");
+      Template->getSpecializations().InsertNode(FTInfo, InsertPos);
     }
     break;
   }

Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=113481&r1=113480&r2=113481&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Thu Sep  9 06:28:23 2010
@@ -237,8 +237,7 @@
   case FunctionDecl::TK_FunctionTemplateSpecialization: {
     FunctionTemplateSpecializationInfo *
       FTSInfo = D->getTemplateSpecializationInfo();
-    // We want it canonical to guarantee that it has a Common*.
-    Writer.AddDeclRef(FTSInfo->getTemplate()->getCanonicalDecl(), Record);
+    Writer.AddDeclRef(FTSInfo->getTemplate(), Record);
     Record.push_back(FTSInfo->getTemplateSpecializationKind());
     
     // Template arguments.





More information about the cfe-commits mailing list