From b0e33d499d97b69f795cb53f8934bcd134a56b5a Mon Sep 17 00:00:00 2001 From: Axel Naumann Date: Mon, 1 Oct 2012 09:18:00 +0000 Subject: [PATCH] Also merge template redeclarations. Don't require specializations (of existing and read template) to be unique. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164931 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Serialization/ASTReaderDecl.cpp | 20 +++++++++++++------- test/Modules/Inputs/redecl-merge-left.h | 7 +++++++ test/Modules/Inputs/redecl-merge-right.h | 7 +++++++ test/Modules/redecl-merge.m | 3 +++ 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index 843893d90f..fb4192f86a 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -1312,10 +1312,12 @@ ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) { D->setMemberSpecialization(); } } - + VisitTemplateDecl(D); D->IdentifierNamespace = Record[Idx++]; - + + mergeRedeclarable(D, Redecl); + return Redecl; } @@ -1402,9 +1404,9 @@ void ASTDeclReader::VisitClassTemplateSpecializationDecl( if (D->isCanonicalDecl()) { // It's kept in the folding set. if (ClassTemplatePartialSpecializationDecl *Partial = dyn_cast(D)) { - CanonPattern->getCommonPtr()->PartialSpecializations.InsertNode(Partial); + CanonPattern->getCommonPtr()->PartialSpecializations.GetOrInsertNode(Partial); } else { - CanonPattern->getCommonPtr()->Specializations.InsertNode(D); + CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D); } } } @@ -1747,7 +1749,7 @@ static bool isSameEntity(NamedDecl *X, NamedDecl *Y) { return (FuncX->getLinkage() == FuncY->getLinkage()) && FuncX->getASTContext().hasSameType(FuncX->getType(), FuncY->getType()); } - + // Variables with the same type and linkage match. if (VarDecl *VarX = dyn_cast(X)) { VarDecl *VarY = cast(Y); @@ -1760,7 +1762,11 @@ static bool isSameEntity(NamedDecl *X, NamedDecl *Y) { NamespaceDecl *NamespaceY = cast(Y); return NamespaceX->isInline() == NamespaceY->isInline(); } - + + // Identical template names and kinds match. + if (isa(X)) + return true; + // FIXME: Many other cases to implement. return false; } @@ -2296,7 +2302,7 @@ void ASTReader::loadPendingDeclChain(serialization::GlobalDeclID ID) { } MergedDeclsMap::iterator MergedPos = combineStoredMergedDecls(CanonDecl, ID); if (MergedPos != MergedDecls.end()) - SearchDecls.append(MergedPos->second.begin(), MergedPos->second.end()); + SearchDecls.append(MergedPos->second.begin(), MergedPos->second.end()); // Build up the list of redeclarations. RedeclChainVisitor Visitor(*this, SearchDecls, RedeclsDeserialized, CanonID); diff --git a/test/Modules/Inputs/redecl-merge-left.h b/test/Modules/Inputs/redecl-merge-left.h index 4bdd01570f..a6ea6024c8 100644 --- a/test/Modules/Inputs/redecl-merge-left.h +++ b/test/Modules/Inputs/redecl-merge-left.h @@ -88,6 +88,13 @@ template<> class List { public: void push_back(int); }; + +namespace N { +template class Set { +public: + void insert(T); +}; +} #endif // Make sure this doesn't introduce an ambiguity-creating 'id' at the diff --git a/test/Modules/Inputs/redecl-merge-right.h b/test/Modules/Inputs/redecl-merge-right.h index 695327674f..2e05c035c5 100644 --- a/test/Modules/Inputs/redecl-merge-right.h +++ b/test/Modules/Inputs/redecl-merge-right.h @@ -89,6 +89,13 @@ template<> class List { public: void push_back(int); }; + +namespace N { + template class Set { + public: + void insert(T); + }; +} #endif int ONE; diff --git a/test/Modules/redecl-merge.m b/test/Modules/redecl-merge.m index 0e5cd4ac37..96b0b47565 100644 --- a/test/Modules/redecl-merge.m +++ b/test/Modules/redecl-merge.m @@ -153,6 +153,9 @@ void testVector() { List list_bool; list_bool.push_back(false); + + N::Set set_char; + set_char.insert('A'); } #endif -- 2.40.0