[cfe-commits] r107783 - in /cfe/trunk: include/clang/Frontend/PCHReader.h lib/Frontend/PCHReader.cpp lib/Frontend/PCHReaderDecl.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Wed Jul 7 08:46:26 PDT 2010


Author: akirtzidis
Date: Wed Jul  7 10:46:26 2010
New Revision: 107783

URL: http://llvm.org/viewvc/llvm-project?rev=107783&view=rev
Log:
Delay passing InterestingDecls to the Consumer until when we know we are not in recursive loading and the
declarations are fully initialized.

Modified:
    cfe/trunk/include/clang/Frontend/PCHReader.h
    cfe/trunk/lib/Frontend/PCHReader.cpp
    cfe/trunk/lib/Frontend/PCHReaderDecl.cpp

Modified: cfe/trunk/include/clang/Frontend/PCHReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHReader.h?rev=107783&r1=107782&r2=107783&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHReader.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHReader.h Wed Jul  7 10:46:26 2010
@@ -453,7 +453,7 @@
   /// "Interesting" declarations are those that have data that may
   /// need to be emitted, such as inline function definitions or
   /// Objective-C protocols.
-  llvm::SmallVector<Decl *, 16> InterestingDecls;
+  std::deque<Decl *> InterestingDecls;
 
   /// \brief When reading a Stmt tree, Stmt operands are placed in this stack.
   llvm::SmallVector<Stmt *, 16> StmtStack;
@@ -519,6 +519,8 @@
   void LoadedDecl(unsigned Index, Decl *D);
   Decl *ReadDeclRecord(uint64_t Offset, unsigned Index);
 
+  void PassInterestingDeclsToConsumer();
+
   /// \brief Produce an error diagnostic and return true.
   ///
   /// This routine should only be used for fatal errors that have to

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=107783&r1=107782&r2=107783&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Wed Jul  7 10:46:26 2010
@@ -2692,6 +2692,15 @@
   return const_cast<DeclContext*>(DC)->lookup(Name);
 }
 
+void PCHReader::PassInterestingDeclsToConsumer() {
+  assert(Consumer);
+  while (!InterestingDecls.empty()) {
+    DeclGroupRef DG(InterestingDecls.front());
+    InterestingDecls.pop_front();
+    Consumer->HandleTopLevelDecl(DG);
+  }
+}
+
 void PCHReader::StartTranslationUnit(ASTConsumer *Consumer) {
   this->Consumer = Consumer;
 
@@ -2699,15 +2708,12 @@
     return;
 
   for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) {
-    // Force deserialization of this decl, which will cause it to be passed to
-    // the consumer (or queued).
+    // Force deserialization of this decl, which will cause it to be queued for
+    // passing to the consumer.
     GetDecl(ExternalDefinitions[I]);
   }
 
-  for (unsigned I = 0, N = InterestingDecls.size(); I != N; ++I) {
-    DeclGroupRef DG(InterestingDecls[I]);
-    Consumer->HandleTopLevelDecl(DG);
-  }
+  PassInterestingDeclsToConsumer();
 }
 
 void PCHReader::PrintStats() {
@@ -3340,6 +3346,11 @@
                                      true);
       Reader.PendingIdentifierInfos.pop_front();
     }
+
+    // We are not in recursive loading, so it's safe to pass the "interesting"
+    // decls to the consumer.
+    if (Reader.Consumer)
+      Reader.PassInterestingDeclsToConsumer();
   }
 
   Reader.CurrentlyLoadingTypeOrDecl = Parent;

Modified: cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderDecl.cpp?rev=107783&r1=107782&r2=107783&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderDecl.cpp Wed Jul  7 10:46:26 2010
@@ -1474,16 +1474,11 @@
   assert(Idx == Record.size());
 
   // 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);
-    }
-  }
+  // 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 (isConsumerInterestedIn(D))
+    InterestingDecls.push_back(D);
 
   return D;
 }





More information about the cfe-commits mailing list