[cfe-commits] r149320 - in /cfe/trunk: include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h lib/StaticAnalyzer/Core/ExplodedGraph.cpp

Ted Kremenek kremenek at apple.com
Mon Jan 30 17:20:02 PST 2012


Author: kremenek
Date: Mon Jan 30 19:20:02 2012
New Revision: 149320

URL: http://llvm.org/viewvc/llvm-project?rev=149320&view=rev
Log:
Minor refactor within ExplodedGraph::reclaimRecentlyAllocatedNodes().  No functionality change.

Modified:
    cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
    cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h?rev=149320&r1=149319&r2=149320&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h Mon Jan 30 19:20:02 2012
@@ -367,6 +367,10 @@
   /// Reclaim "uninteresting" nodes created since the last time this method
   /// was called.
   void reclaimRecentlyAllocatedNodes();
+
+private:
+  bool shouldCollect(const ExplodedNode *node);
+  void collectNode(ExplodedNode *node);
 };
 
 class ExplodedNodeSet {

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp?rev=149320&r1=149319&r2=149320&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp Mon Jan 30 19:20:02 2012
@@ -66,20 +66,7 @@
 // Node reclamation.
 //===----------------------------------------------------------------------===//
 
-void ExplodedGraph::reclaimRecentlyAllocatedNodes() {
-  if (!recentlyAllocatedNodes)
-    return;
-
-  // Only periodically relcaim nodes so that we can build up a set of
-  // nodes that meet the reclamation criteria.  Freshly created nodes
-  // by definition have no successor, and thus cannot be reclaimed (see below).
-  assert(reclaimCounter > 0);
-  if (--reclaimCounter != 0)
-    return;
-  reclaimCounter = CounterTop;
-  
-  NodeList &nl = *getNodeList(recentlyAllocatedNodes);
- 
+bool ExplodedGraph::shouldCollect(const ExplodedNode *node) {
   // Reclaimn all nodes that match *all* the following criteria:
   //
   // (1) 1 predecessor (that has one successor)
@@ -90,61 +77,86 @@
   // (6) The 'GDM' is the same as the predecessor.
   // (7) The LocationContext is the same as the predecessor.
   // (8) The PostStmt is for a non-consumed Stmt or Expr.
-  
-  for (NodeList::iterator i = nl.begin(), e = nl.end() ; i != e; ++i) {
-    ExplodedNode *node = *i;
-    
-    // Conditions 1 and 2.
-    if (node->pred_size() != 1 || node->succ_size() != 1)
-      continue;
-
-    ExplodedNode *pred = *(node->pred_begin());
-    if (pred->succ_size() != 1)
-      continue;
 
-    ExplodedNode *succ = *(node->succ_begin());
-    if (succ->pred_size() != 1)
-      continue;
+  // Conditions 1 and 2.
+  if (node->pred_size() != 1 || node->succ_size() != 1)
+    return false;
+
+  const ExplodedNode *pred = *(node->pred_begin());
+  if (pred->succ_size() != 1)
+    return false;
+  
+  const ExplodedNode *succ = *(node->succ_begin());
+  if (succ->pred_size() != 1)
+    return false;
+
+  // Condition 3.
+  ProgramPoint progPoint = node->getLocation();
+  if (!isa<PostStmt>(progPoint) ||
+      (isa<CallEnter>(progPoint) || isa<CallExit>(progPoint)))
+    return false;
+
+  // Condition 4.
+  PostStmt ps = cast<PostStmt>(progPoint);
+  if (ps.getTag())
+    return false;
+  
+  if (isa<BinaryOperator>(ps.getStmt()))
+    return false;
 
-    // Condition 3.
-    ProgramPoint progPoint = node->getLocation();
-    if (!isa<PostStmt>(progPoint) ||
-        (isa<CallEnter>(progPoint) || isa<CallExit>(progPoint)))
-      continue;
-    // Condition 4.
-    PostStmt ps = cast<PostStmt>(progPoint);
-    if (ps.getTag())
-      continue;
+  // Conditions 5, 6, and 7.
+  ProgramStateRef state = node->getState();
+  ProgramStateRef pred_state = pred->getState();    
+  if (state->store != pred_state->store || state->GDM != pred_state->GDM ||
+      progPoint.getLocationContext() != pred->getLocationContext())
+    return false;
+  
+  // Condition 8.
+  if (const Expr *Ex = dyn_cast<Expr>(ps.getStmt())) {
+    ParentMap &PM = progPoint.getLocationContext()->getParentMap();
+    if (!PM.isConsumedExpr(Ex))
+      return false;
+  }
+  
+  return true; 
+}
 
-    if (isa<BinaryOperator>(ps.getStmt()))
-      continue;
+void ExplodedGraph::collectNode(ExplodedNode *node) {
+  // Removing a node means:
+  // (a) changing the predecessors successor to the successor of this node
+  // (b) changing the successors predecessor to the predecessor of this node
+  // (c) Putting 'node' onto freeNodes.
+  assert(node->pred_size() == 1 || node->succ_size() == 1);
+  ExplodedNode *pred = *(node->pred_begin());
+  ExplodedNode *succ = *(node->succ_begin());
+  pred->replaceSuccessor(succ);
+  succ->replacePredecessor(pred);
+  if (!freeNodes)
+    freeNodes = new NodeList();
+  getNodeList(freeNodes)->push_back(node);
+  Nodes.RemoveNode(node);
+  --NumNodes;
+  node->~ExplodedNode();  
+}
 
-    // Conditions 5, 6, and 7.
-    ProgramStateRef state = node->getState();
-    ProgramStateRef pred_state = pred->getState();    
-    if (state->store != pred_state->store || state->GDM != pred_state->GDM ||
-        progPoint.getLocationContext() != pred->getLocationContext())
-      continue;
+void ExplodedGraph::reclaimRecentlyAllocatedNodes() {
+  if (!recentlyAllocatedNodes)
+    return;
 
-    // Condition 8.
-    if (const Expr *Ex = dyn_cast<Expr>(ps.getStmt())) {
-      ParentMap &PM = progPoint.getLocationContext()->getParentMap();
-      if (!PM.isConsumedExpr(Ex))
-        continue;
-    }
-    
-    // If we reach here, we can remove the node.  This means:
-    // (a) changing the predecessors successor to the successor of this node
-    // (b) changing the successors predecessor to the predecessor of this node
-    // (c) Putting 'node' onto freeNodes.
-    pred->replaceSuccessor(succ);
-    succ->replacePredecessor(pred);
-    if (!freeNodes)
-      freeNodes = new NodeList();
-    getNodeList(freeNodes)->push_back(node);
-    Nodes.RemoveNode(node);
-    --NumNodes;
-    node->~ExplodedNode();
+  // Only periodically relcaim nodes so that we can build up a set of
+  // nodes that meet the reclamation criteria.  Freshly created nodes
+  // by definition have no successor, and thus cannot be reclaimed (see below).
+  assert(reclaimCounter > 0);
+  if (--reclaimCounter != 0)
+    return;
+  reclaimCounter = CounterTop;
+  
+  NodeList &nl = *getNodeList(recentlyAllocatedNodes);
+  
+  for (NodeList::iterator i = nl.begin(), e = nl.end() ; i != e; ++i) {
+    ExplodedNode *node = *i;    
+    if (shouldCollect(node))
+      collectNode(node);
   }
   
   nl.clear();





More information about the cfe-commits mailing list