From: Douglas Gregor Date: Wed, 3 Oct 2012 18:34:48 +0000 (+0000) Subject: Revert most of the functionality in r165001. Instead, make sure that X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e5fa3c26919c0fa9817fbbb967f1a418e2fd3140;p=clang Revert most of the functionality in r165001. Instead, make sure that the ASTReader doesn't attach a body to a function that is already defined elsewhere. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165137 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h index 7c5259732d..af69148140 100644 --- a/include/clang/Serialization/ASTReader.h +++ b/include/clang/Serialization/ASTReader.h @@ -687,12 +687,6 @@ private: /// Objective-C protocols. std::deque InterestingDecls; - /// \brief Redecls that have been added to the AST - /// - /// Redecls that are deserialized but not in RedeclsAddedToAST must - /// not be passed to the ASTConsumers, even if they are InterestignDecls. - llvm::SmallPtrSet RedeclsAddedToAST; - /// \brief The set of redeclarable declarations that have been deserialized /// since the last time the declaration chains were linked. llvm::SmallPtrSet RedeclsDeserialized; diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index cc6d073b10..f5de6c4bd9 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -5614,10 +5614,7 @@ void ASTReader::ReadPendingInstantiations( SourceLocation Loc = SourceLocation::getFromRawEncoding(PendingInstantiations[Idx++]); - // For modules, find out whether an instantiation already exists - if (!getContext().getLangOpts().Modules - || needPendingInstantiation(D)) - Pending.push_back(std::make_pair(D, Loc)); + Pending.push_back(std::make_pair(D, Loc)); } PendingInstantiations.clear(); } @@ -6528,5 +6525,4 @@ ASTReader::~ASTReader() { J != F; ++J) delete J->first; } - assert(RedeclsAddedToAST.empty() && "RedeclsAddedToAST not empty!"); } diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index 42ea7946e2..c291b4b240 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -320,7 +320,10 @@ void ASTDeclReader::Visit(Decl *D) { ID->TypeForDecl = Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull(); } else if (FunctionDecl *FD = dyn_cast(D)) { // FunctionDecl's body was written last after all other Stmts/Exprs. - if (Record[Idx++]) + // We only read it if FD doesn't already have a body (e.g., from another + // module). + if (Record[Idx++] && + (!Reader.getContext().getLangOpts().Modules || !FD->hasBody())) FD->setLazyBody(GetCurrentCursorOffset()); } else if (D->isTemplateParameter()) { // If we have a fully initialized template parameter, we can now @@ -1778,11 +1781,9 @@ ASTDeclReader::FindExistingResult::~FindExistingResult() { DeclContext *DC = New->getLexicalDeclContext(); if (DC->isTranslationUnit() && Reader.SemaObj) { - if (Reader.SemaObj->IdResolver.tryAddTopLevelDecl(New, New->getDeclName())) - Reader.RedeclsAddedToAST.insert(New); + Reader.SemaObj->IdResolver.tryAddTopLevelDecl(New, New->getDeclName()); } else if (DC->isNamespace()) { DC->addDecl(New); - Reader.RedeclsAddedToAST.insert(New); } } @@ -2157,13 +2158,7 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) { // AST consumer might need to know about, queue it. // We don't pass it to the consumer immediately because we may be in recursive // loading, and some declarations may still be initializing. - if (getContext().getLangOpts().Modules) { - if (RedeclsAddedToAST.count(D)) { - RedeclsAddedToAST.erase(D); - if (isConsumerInterestedIn(D)) - InterestingDecls.push_back(D); - } - } else if (isConsumerInterestedIn(D)) + if (isConsumerInterestedIn(D)) InterestingDecls.push_back(D); return D;