From: Argyrios Kyrtzidis Date: Mon, 14 Nov 2011 07:07:59 +0000 (+0000) Subject: [PCH] Load the chained objc categories only after recursive loading is finished X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5a174990e84b33b20761f2fde51169400dd87f2e;p=clang [PCH] Load the chained objc categories only after recursive loading is finished otherwise we may crash. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144524 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h index bef02f0d95..7a9a15caf4 100644 --- a/include/clang/Serialization/ASTReader.h +++ b/include/clang/Serialization/ASTReader.h @@ -624,6 +624,11 @@ private: /// deeply nested calls when there are many redeclarations. std::deque > PendingPreviousDecls; + /// \brief We delay loading the chain of objc categories after recursive + /// loading of declarations is finished. + std::vector > + PendingChainedObjCCategories; + /// \brief Ready to load the previous declaration of the given Decl. void loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID); diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 80b582e246..6192fb7751 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -5543,6 +5543,14 @@ void ASTReader::FinishedDeserializing() { 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) diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index 729cde0abf..719f5bc06e 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -1772,9 +1772,11 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) { // Load any relevant update records. loadDeclUpdateRecords(ID, D); - + + // Load the category chain after recursive loading is finished. if (ObjCChainedCategoriesInterfaces.count(ID)) - loadObjCChainedCategories(ID, cast(D)); + PendingChainedObjCCategories.push_back( + std::make_pair(cast(D), ID)); // If we have deserialized a declaration that has a definition the // AST consumer might need to know about, queue it.