Author: akirtzidis Date: Mon Sep 13 06:45:48 2010 New Revision: 113744 URL: http://llvm.org/viewvc/llvm-project?rev=113744&view=rev Log: Fix C++ PCH issue.
The canonical FunctionTemplateDecl contains the specializations but we cannot use getCanonicalDecl on Template because it may still be initializing. Write and read it from PCH. Fixes http://llvm.org/PR8134 Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp cfe/trunk/lib/Serialization/ASTWriterDecl.cpp cfe/trunk/test/PCH/cxx-templates.h Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=113744&r1=113743&r2=113744&view=diff ============================================================================== --- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original) +++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Mon Sep 13 06:45:48 2010 @@ -294,6 +294,10 @@ FD->TemplateOrSpecialization = FTInfo; if (FD->isCanonicalDecl()) { // if canonical add to template's set. + // The template that contains the specializations set. It's not safe to + // use getCanonicalDecl on Template since it may still be initializing. + FunctionTemplateDecl *CanonTemplate + = cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++])); // Get the InsertPos by FindNodeOrInsertPos() instead of calling // InsertNode(FTInfo) directly to avoid the getASTContext() call in // FunctionTemplateSpecializationInfo's Profile(). @@ -303,9 +307,9 @@ FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs.data(), TemplArgs.size(), C); void *InsertPos = 0; - Template->getSpecializations().FindNodeOrInsertPos(ID, InsertPos); + CanonTemplate->getSpecializations().FindNodeOrInsertPos(ID, InsertPos); assert(InsertPos && "Another specialization already inserted!"); - Template->getSpecializations().InsertNode(FTInfo, InsertPos); + CanonTemplate->getSpecializations().InsertNode(FTInfo, InsertPos); } break; } @@ -1041,7 +1045,7 @@ // Read the function specialization declarations. // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled - // through the specialized FunctionDecl's setFunctionTemplateSpecialization. + // when reading the specialized FunctionDecl. unsigned NumSpecs = Record[Idx++]; while (NumSpecs--) Reader.GetDecl(Record[Idx++]); Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=113744&r1=113743&r2=113744&view=diff ============================================================================== --- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original) +++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Mon Sep 13 06:45:48 2010 @@ -257,6 +257,12 @@ } Writer.AddSourceLocation(FTSInfo->getPointOfInstantiation(), Record); + + if (D->isCanonicalDecl()) { + // Write the template that contains the specializations set. We will + // add a FunctionTemplateSpecializationInfo to it when reading. + Writer.AddDeclRef(FTSInfo->getTemplate()->getCanonicalDecl(), Record); + } break; } case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { Modified: cfe/trunk/test/PCH/cxx-templates.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/cxx-templates.h?rev=113744&r1=113743&r2=113744&view=diff ============================================================================== --- cfe/trunk/test/PCH/cxx-templates.h (original) +++ cfe/trunk/test/PCH/cxx-templates.h Mon Sep 13 06:45:48 2010 @@ -145,3 +145,8 @@ template <typename T> TS5(T y) : s(y) {} }; + +// PR 8134 +template<class T> void f_PR8134(T); +template<class T> void f_PR8134(T); +void g_PR8134() { f_PR8134(0); f_PR8134('x'); } _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
