[cfe-commits] r157762 - /cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Anna Zaks ganna at apple.com
Thu May 31 11:07:55 PDT 2012


Author: zaks
Date: Thu May 31 13:07:55 2012
New Revision: 157762

URL: http://llvm.org/viewvc/llvm-project?rev=157762&view=rev
Log:
[analyzer] Cleanup for r157721.
We should lock the number of elements after the initial parsing is
complete. Recursive AST visitors in AnalyzesConsumer and CallGarph can
trigger lazy pch deserialization resulting in more calls to
HandleTopLevelDecl and appending to the LocalTUDecls list. We should
ignore those.

Modified:
    cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp?rev=157762&r1=157761&r2=157762&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp Thu May 31 13:07:55 2012
@@ -230,7 +230,7 @@
 
   /// \brief Build the call graph for all the top level decls of this TU and
   /// use it to define the order in which the functions should be visited.
-  void HandleDeclsGallGraph();
+  void HandleDeclsGallGraph(const unsigned LocalTUDeclsSize);
 
   /// \brief Run analyzes(syntax or path sensitive) on the given function.
   /// \param Mode - determines if we are requesting syntax only or path
@@ -311,18 +311,16 @@
   }
 }
 
-void AnalysisConsumer::HandleDeclsGallGraph() {
+void AnalysisConsumer::HandleDeclsGallGraph(const unsigned LocalTUDeclsSize) {
   // Otherwise, use the Callgraph to derive the order.
   // Build the Call Graph.
   CallGraph CG;
 
   // Add all the top level declarations to the graph.
-  // Note: TraverseDecl may modify LocalTUDecls, but only by appending more
-  // entries.  Thus we don't use an iterator, but rely on LocalTUDecls
-  // random access.  By doing so, we automatically compensate for iterators
-  // possibly being invalidated, although this is a bit slower.
-  const unsigned n = LocalTUDecls.size();
-  for (unsigned i = 0 ; i < n ; ++i) {
+  // Note: CallGraph can trigger deserialization of more items from a pch
+  // (though HandleInterestingDecl); triggering additions to LocalTUDecls.
+  // We rely on random access to add the initially processed Decls to CG.
+  for (unsigned i = 0 ; i < LocalTUDeclsSize ; ++i) {
     CG.addToCallGraph(LocalTUDecls[i]);
   }
 
@@ -414,13 +412,13 @@
     // entries.  Thus we don't use an iterator, but rely on LocalTUDecls
     // random access.  By doing so, we automatically compensate for iterators
     // possibly being invalidated, although this is a bit slower.
-    const unsigned n = LocalTUDecls.size();
-    for (unsigned i = 0 ; i < n ; ++i) {
+    const unsigned LocalTUDeclsSize = LocalTUDecls.size();
+    for (unsigned i = 0 ; i < LocalTUDeclsSize ; ++i) {
       TraverseDecl(LocalTUDecls[i]);
     }
 
     if (Mgr->shouldInlineCall())
-      HandleDeclsGallGraph();
+      HandleDeclsGallGraph(LocalTUDeclsSize);
 
     // After all decls handled, run checkers on the entire TranslationUnit.
     checkerMgr->runCheckersOnEndOfTranslationUnit(TU, *Mgr, BR);





More information about the cfe-commits mailing list