From da32f5c42246a4f2fd82bdd133781c5dd786c9e2 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Sat, 17 Dec 2011 08:11:25 +0000 Subject: [PATCH] [PCH] Don't deserialize bodies of interesting decls while iterating over them because more interesting decls can be added during body deserialization. Should fix msvc build tests. llvm-svn: 146824 --- clang/include/clang/Serialization/ASTReader.h | 2 + clang/lib/Serialization/ASTReader.cpp | 86 ++++++++++--------- 2 files changed, 49 insertions(+), 39 deletions(-) diff --git a/clang/include/clang/Serialization/ASTReader.h b/clang/include/clang/Serialization/ASTReader.h index e145cb74b24a..0947dfc4eb75 100644 --- a/clang/include/clang/Serialization/ASTReader.h +++ b/clang/include/clang/Serialization/ASTReader.h @@ -790,6 +790,8 @@ private: void PassInterestingDeclsToConsumer(); void PassInterestingDeclToConsumer(Decl *D); + void finishPendingActions(); + /// \brief Produce an error diagnostic and return true. /// /// This routine should only be used for fatal errors that have to diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 00f7b7ad0e3b..3af04c2bc8ad 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -6024,56 +6024,64 @@ void ASTReader::ClearSwitchCaseIDs() { SwitchCaseStmts.clear(); } +void ASTReader::finishPendingActions() { + while (!PendingIdentifierInfos.empty() || + !PendingPreviousDecls.empty() || + !PendingChainedObjCCategories.empty()) { + + // If any identifiers with corresponding top-level declarations have + // been loaded, load those declarations now. + while (!PendingIdentifierInfos.empty()) { + SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, + PendingIdentifierInfos.front().DeclIDs, true); + PendingIdentifierInfos.pop_front(); + } + + // Ready to load previous declarations of Decls that were delayed. + while (!PendingPreviousDecls.empty()) { + loadAndAttachPreviousDecl(PendingPreviousDecls.front().first, + PendingPreviousDecls.front().second); + PendingPreviousDecls.pop_front(); + } + + for (std::vector >::iterator + I = PendingChainedObjCCategories.begin(), + E = PendingChainedObjCCategories.end(); I != E; ++I) { + loadObjCChainedCategories(I->second, I->first); + } + PendingChainedObjCCategories.clear(); + } +} + void ASTReader::FinishedDeserializing() { assert(NumCurrentElementsDeserializing && "FinishedDeserializing not paired with StartedDeserializing"); if (NumCurrentElementsDeserializing == 1) { - // Fully load the interesting decls, including deserializing their bodies, - // so that any other declarations that get referenced in the body will be - // fully deserialized by the time we pass them to the consumer. - for (std::deque::iterator - I = InterestingDecls.begin(), - E = InterestingDecls.end(); I != E; ++I) - (*I)->getBody(); + while (Consumer && !InterestingDecls.empty()) { + finishPendingActions(); - do { - // If any identifiers with corresponding top-level declarations have - // been loaded, load those declarations now. - while (!PendingIdentifierInfos.empty()) { - SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, - PendingIdentifierInfos.front().DeclIDs, true); - PendingIdentifierInfos.pop_front(); - } - - // Ready to load previous declarations of Decls that were delayed. - while (!PendingPreviousDecls.empty()) { - loadAndAttachPreviousDecl(PendingPreviousDecls.front().first, - PendingPreviousDecls.front().second); - PendingPreviousDecls.pop_front(); - } - - for (std::vector >::iterator - I = PendingChainedObjCCategories.begin(), - E = PendingChainedObjCCategories.end(); I != E; ++I) { - loadObjCChainedCategories(I->second, I->first); - } - PendingChainedObjCCategories.clear(); - // We are not in recursive loading, so it's safe to pass the "interesting" // decls to the consumer. - if (Consumer && !InterestingDecls.empty()) { - Decl *D = InterestingDecls.front(); - InterestingDecls.pop_front(); + Decl *D = InterestingDecls.front(); + InterestingDecls.pop_front(); - PassInterestingDeclToConsumer(D); + // Fully load the interesting decls, including deserializing their + // bodies, so that any other declarations that get referenced in the + // body will be fully deserialized by the time we pass them to the + // consumer. + if (FunctionDecl *FD = dyn_cast(D)) { + if (FD->doesThisDeclarationHaveABody()) { + FD->getBody(); + finishPendingActions(); + } } - } while ((Consumer && !InterestingDecls.empty()) || - !PendingIdentifierInfos.empty() || - !PendingPreviousDecls.empty() || - !PendingChainedObjCCategories.empty()); + PassInterestingDeclToConsumer(D); + } + + finishPendingActions(); assert(PendingForwardRefs.size() == 0 && "Some forward refs did not get linked to the definition!");