From f005eac566a3b6e506d6437305805907ed4313d7 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Sat, 25 Apr 2009 00:41:30 +0000 Subject: Make sure that the consumer sees all interested decls. This fixes Preview llvm-svn: 70007 --- clang/lib/Frontend/PCHReader.cpp | 41 +++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'clang/lib/Frontend/PCHReader.cpp') diff --git a/clang/lib/Frontend/PCHReader.cpp b/clang/lib/Frontend/PCHReader.cpp index b10778a1e1d..4c3e248c64a 100644 --- a/clang/lib/Frontend/PCHReader.cpp +++ b/clang/lib/Frontend/PCHReader.cpp @@ -2404,6 +2404,20 @@ inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) { DeclOffsets[Index] = reinterpret_cast(D); } +/// \brief Determine whether the consumer will be interested in seeing +/// this declaration (via HandleTopLevelDecl). +/// +/// This routine should return true for anything that might affect +/// code generation, e.g., inline function definitions, Objective-C +/// declarations with metadata, etc. +static bool isConsumerInterestedIn(Decl *D) { + if (VarDecl *Var = dyn_cast(D)) + return Var->isFileVarDecl() && Var->getInit(); + if (FunctionDecl *Func = dyn_cast(D)) + return Func->isThisDeclarationADefinition(); + return isa(D); +} + /// \brief Read the declaration at the given offset from the PCH file. Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) { // Keep track of where we are in the stream, then jump back there @@ -2581,23 +2595,15 @@ Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) { } assert(Idx == Record.size()); - if (Consumer) { - // If we have deserialized a declaration that has a definition the - // AST consumer might need to know about, notify the consumer - // about that definition now. - if (VarDecl *Var = dyn_cast(D)) { - if (Var->isFileVarDecl() && Var->getInit()) { - DeclGroupRef DG(Var); - Consumer->HandleTopLevelDecl(DG); - } - } else if (FunctionDecl *Func = dyn_cast(D)) { - if (Func->isThisDeclarationADefinition()) { - DeclGroupRef DG(Func); - Consumer->HandleTopLevelDecl(DG); - } - } else if (isa(D)) { + // If we have deserialized a declaration that has a definition the + // AST consumer might need to know about, notify the consumer + // about that definition now or queue it for later. + if (isConsumerInterestedIn(D)) { + if (Consumer) { DeclGroupRef DG(D); Consumer->HandleTopLevelDecl(DG); + } else { + InterestingDecls.push_back(D); } } @@ -2755,6 +2761,11 @@ void PCHReader::StartTranslationUnit(ASTConsumer *Consumer) { DeclGroupRef DG(D); Consumer->HandleTopLevelDecl(DG); } + + for (unsigned I = 0, N = InterestingDecls.size(); I != N; ++I) { + DeclGroupRef DG(InterestingDecls[I]); + Consumer->HandleTopLevelDecl(DG); + } } void PCHReader::PrintStats() { -- cgit v1.2.3