[cfe-commits] r47766 - in /cfe/trunk: Analysis/GRCoreEngine.cpp Analysis/GRExprEngine.cpp include/clang/Analysis/PathSensitive/GRCoreEngine.h include/clang/Analysis/PathSensitive/GRExprEngine.h

Ted Kremenek kremenek at apple.com
Fri Feb 29 12:27:50 PST 2008


Author: kremenek
Date: Fri Feb 29 14:27:50 2008
New Revision: 47766

URL: http://llvm.org/viewvc/llvm-project?rev=47766&view=rev
Log:
"Refinement" of hack to bound loop-traversals: visit any block at a maximum of 3 times along a given path.

Modified:
    cfe/trunk/Analysis/GRCoreEngine.cpp
    cfe/trunk/Analysis/GRExprEngine.cpp
    cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h
    cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h

Modified: cfe/trunk/Analysis/GRCoreEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/GRCoreEngine.cpp?rev=47766&r1=47765&r2=47766&view=diff

==============================================================================
--- cfe/trunk/Analysis/GRCoreEngine.cpp (original)
+++ cfe/trunk/Analysis/GRCoreEngine.cpp Fri Feb 29 14:27:50 2008
@@ -136,11 +136,11 @@
     // This path is done. Don't enqueue any more nodes.
     return;
   }
+
+  // FIXME: Should we allow ProcessBlockEntrance to also manipulate state?
   
-  // FIXME: we will dispatch to a function that
-  //  manipulates the state at the entrance to a block.
-  
-  GenerateNode(BlockEntrance(Blk), Pred->State, Pred);
+  if (ProcessBlockEntrance(Blk, Pred->State, WList->getBlockCounter()))
+    GenerateNode(BlockEntrance(Blk), Pred->State, Pred);
 }
 
 void GRCoreEngineImpl::HandleBlockEntrance(const BlockEntrance& L,

Modified: cfe/trunk/Analysis/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/GRExprEngine.cpp?rev=47766&r1=47765&r2=47766&view=diff

==============================================================================
--- cfe/trunk/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/Analysis/GRExprEngine.cpp Fri Feb 29 14:27:50 2008
@@ -147,6 +147,12 @@
   }
 }
 
+bool GRExprEngine::ProcessBlockEntrance(CFGBlock* B, ValueState*,
+                                        GRBlockCounter BC) {
+  
+  return BC.getNumVisited(B->getBlockID()) < 3;
+}
+
 void GRExprEngine::ProcessBranch(Expr* Condition, Stmt* Term,
                                  BranchNodeBuilder& builder) {
 
@@ -156,15 +162,6 @@
   // Check for NULL conditions; e.g. "for(;;)"
   if (!Condition) { 
     builder.markInfeasible(false);
-    
-    // Get the current block counter.
-    GRBlockCounter BC = builder.getBlockCounter();
-    unsigned BlockID = builder.getTargetBlock(true)->getBlockID();
-    unsigned NumVisited = BC.getNumVisited(BlockID);
-        
-    if (NumVisited < 1) builder.generateNode(PrevState, true);
-    else builder.markInfeasible(true);
-
     return;
   }
   
@@ -191,46 +188,25 @@
       return;
     }      
   }
-  
-  // Get the current block counter.
-  GRBlockCounter BC = builder.getBlockCounter();
-  unsigned BlockID = builder.getTargetBlock(true)->getBlockID();
-  unsigned NumVisited = BC.getNumVisited(BlockID);
-  
-  if (isa<nonlval::ConcreteInt>(V) || 
-      BC.getNumVisited(builder.getTargetBlock(true)->getBlockID()) < 1) {
     
-    // Process the true branch.
 
-    bool isFeasible = true;
-    
-    ValueState* St = Assume(PrevState, V, true, isFeasible);
+  // Process the true branch.
 
-    if (isFeasible)
-      builder.generateNode(MarkBranch(St, Term, true), true);
-    else
-      builder.markInfeasible(true);
-  }
+  bool isFeasible = true;  
+  ValueState* St = Assume(PrevState, V, true, isFeasible);
+
+  if (isFeasible)
+    builder.generateNode(MarkBranch(St, Term, true), true);
   else
     builder.markInfeasible(true);
+      
+  // Process the false branch.  
   
-  BlockID = builder.getTargetBlock(false)->getBlockID();
-  NumVisited = BC.getNumVisited(BlockID);
+  isFeasible = false;
+  St = Assume(PrevState, V, false, isFeasible);
   
-  if (isa<nonlval::ConcreteInt>(V) || 
-      BC.getNumVisited(builder.getTargetBlock(false)->getBlockID()) < 1) {
-    
-    // Process the false branch.  
-    
-    bool isFeasible = false;
-    
-    ValueState* St = Assume(PrevState, V, false, isFeasible);
-    
-    if (isFeasible)
-      builder.generateNode(MarkBranch(St, Term, false), false);
-    else
-      builder.markInfeasible(false);
-  }
+  if (isFeasible)
+    builder.generateNode(MarkBranch(St, Term, false), false);
   else
     builder.markInfeasible(false);
 }

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h?rev=47766&r1=47765&r2=47766&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h Fri Feb 29 14:27:50 2008
@@ -86,11 +86,14 @@
                     ExplodedNodeImpl* Pred);  
   
   virtual void* ProcessEOP(CFGBlock* Blk, void* State) = 0;  
+  
+  virtual bool ProcessBlockEntrance(CFGBlock* Blk, void* State,
+                                    GRBlockCounter BC) = 0;
 
-  virtual void  ProcessStmt(Stmt* S, GRStmtNodeBuilderImpl& Builder) = 0;
+  virtual void ProcessStmt(Stmt* S, GRStmtNodeBuilderImpl& Builder) = 0;
 
-  virtual void  ProcessBranch(Expr* Condition, Stmt* Terminator,
-                              GRBranchNodeBuilderImpl& Builder) = 0;
+  virtual void ProcessBranch(Expr* Condition, Stmt* Terminator,
+                             GRBranchNodeBuilderImpl& Builder) = 0;
 
   virtual void ProcessIndirectGoto(GRIndirectGotoNodeBuilderImpl& Builder) = 0;
   
@@ -434,6 +437,12 @@
     GRStmtNodeBuilder<CHECKER> Builder(BuilderImpl);
     Checker->ProcessStmt(S, Builder);
   }
+  
+  virtual bool ProcessBlockEntrance(CFGBlock* Blk, void* State,
+                                    GRBlockCounter BC) {    
+    return Checker->ProcessBlockEntrance(Blk,
+                                         GRTrait<StateTy>::toState(State), BC);
+  }
 
   virtual void ProcessBranch(Expr* Condition, Stmt* Terminator,
                              GRBranchNodeBuilderImpl& BuilderImpl) {

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h?rev=47766&r1=47765&r2=47766&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h Fri Feb 29 14:27:50 2008
@@ -211,9 +211,14 @@
   undef_result_iterator undef_results_end() { return UndefResults.end(); }
   
   /// ProcessStmt - Called by GRCoreEngine. Used to generate new successor
-  ///  nodes by processing the 'effects' of a block-level statement.
+  ///  nodes by processing the 'effects' of a block-level statement.  
   void ProcessStmt(Stmt* S, StmtNodeBuilder& builder);    
   
+  /// ProcessBlockEntrance - Called by GRCoreEngine when start processing
+  ///  a CFGBlock.  This method returns true if the analysis should continue
+  ///  exploring the given path, and false otherwise.
+  bool ProcessBlockEntrance(CFGBlock* B, ValueState* St, GRBlockCounter BC);
+  
   /// ProcessBranch - Called by GRCoreEngine.  Used to generate successor
   ///  nodes by processing the 'effects' of a branch condition.
   void ProcessBranch(Expr* Condition, Stmt* Term, BranchNodeBuilder& builder);





More information about the cfe-commits mailing list