[cfe-commits] r53739 - in /cfe/trunk: include/clang/Analysis/PathSensitive/GRExprEngine.h include/clang/Analysis/PathSensitive/GRTransferFuncs.h include/clang/Analysis/PathSensitive/ValueState.h lib/Analysis/GRExprEngine.cpp lib/Analysis/GRTransferFuncs.cpp

Ted Kremenek kremenek at apple.com
Thu Jul 17 14:27:31 PDT 2008


Author: kremenek
Date: Thu Jul 17 16:27:31 2008
New Revision: 53739

URL: http://llvm.org/viewvc/llvm-project?rev=53739&view=rev
Log:
Begin major changes to EvalXXX methods in GRTransferFuncs.  Currently some of the methods only return an RVal; we want them to be able to create an arbitrary number of states.

Modified:
    cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h
    cfe/trunk/include/clang/Analysis/PathSensitive/GRTransferFuncs.h
    cfe/trunk/include/clang/Analysis/PathSensitive/ValueState.h
    cfe/trunk/lib/Analysis/GRExprEngine.cpp
    cfe/trunk/lib/Analysis/GRTransferFuncs.cpp

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=53739&r1=53738&r2=53739&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h Thu Jul 17 16:27:31 2008
@@ -609,6 +609,10 @@
       return TF->EvalBinOp(*this, Op, cast<NonLVal>(L), cast<NonLVal>(R));
   }
   
+  void EvalBinOp(ExplodedNodeSet<ValueState>& Dst, Expr* E,
+                 BinaryOperator::Opcode Op,
+                 NonLVal L, NonLVal R, ExplodedNode<ValueState>* Pred);
+  
   void EvalCall(NodeSet& Dst, CallExpr* CE, RVal L, NodeTy* Pred) {
     assert (Builder && "GRStmtNodeBuilder must be defined.");
     TF->EvalCall(Dst, *this, *Builder, CE, L, Pred);

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

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRTransferFuncs.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRTransferFuncs.h Thu Jul 17 16:27:31 2008
@@ -49,7 +49,16 @@
   // Binary Operators.
   
   virtual RVal EvalBinOp(GRExprEngine& Engine, BinaryOperator::Opcode Op,
-                         NonLVal L, NonLVal R) = 0;
+                         NonLVal L, NonLVal R) {
+    return UnknownVal();
+  }
+  
+  virtual void EvalBinOpNN(ExplodedNodeSet<ValueState>& Dst,
+                           GRExprEngine& Engine,
+                           GRStmtNodeBuilder<ValueState>& Builder,
+                           BinaryOperator::Opcode Op, Expr* Ex,
+                           NonLVal L, NonLVal R,
+                           ExplodedNode<ValueState>* Pred);
   
   virtual RVal EvalBinOp(GRExprEngine& Engine, BinaryOperator::Opcode Op,
                          LVal L, LVal R) = 0;

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

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/ValueState.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/ValueState.h Thu Jul 17 16:27:31 2008
@@ -185,6 +185,7 @@
   
   
 class ValueStateManager {
+  friend class GRExprEngine;
   
 private:
   EnvironmentManager                   EnvMgr;
@@ -210,6 +211,13 @@
   ///  This vector is persistent because it is reused over and over.
   StoreManager::DeclRootsTy DRoots;
   
+  /// CurrentStmt - The block-level statement currently being visited.  This
+  ///  is set by GRExprEngine.
+  Stmt* CurrentStmt;
+  
+  /// cfg - The CFG for the analyzed function/method.
+  CFG& cfg;
+  
 private:
 
   Environment RemoveBlkExpr(const Environment& Env, Expr* E) {
@@ -223,7 +231,7 @@
     
 public:  
   ValueStateManager(ASTContext& Ctx, StoreManager* stmgr,
-                    llvm::BumpPtrAllocator& alloc) 
+                    llvm::BumpPtrAllocator& alloc, CFG& c) 
   : EnvMgr(alloc),
     StMgr(stmgr),
     ISetFactory(alloc), 
@@ -231,7 +239,8 @@
     CEFactory(alloc),
     BasicVals(Ctx, alloc),
     SymMgr(alloc),
-    Alloc(alloc) {}
+    Alloc(alloc),
+    cfg(c) {}
 
   const ValueState* getInitialState();
         
@@ -273,6 +282,20 @@
     NewSt.Env = NewEnv;
     return getPersistentState(NewSt);
   }
+  
+  const ValueState* SetRVal(const ValueState* St, Expr* Ex, RVal V) {
+    
+    bool isBlkExpr = false;
+    
+    if (Ex == CurrentStmt) {
+      isBlkExpr = cfg.isBlkExpr(Ex);
+      
+      if (!isBlkExpr)
+        return St;
+    }
+    
+    return SetRVal(St, Ex, V, isBlkExpr, true);
+  }
 
   // Methods that query & manipulate the Store.
 

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

==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngine.cpp Thu Jul 17 16:27:31 2008
@@ -121,7 +121,7 @@
     Liveness(L),
     Builder(NULL),
     StateMgr(G.getContext(), CreateBasicStoreManager(G.getAllocator()),
-             G.getAllocator()),
+             G.getAllocator(), G.getCFG()),
     BasicVals(StateMgr.getBasicValueFactory()),
     TF(NULL), // FIXME
     SymMgr(StateMgr.getSymbolManager()),
@@ -242,7 +242,10 @@
   
   Builder = &builder;
   EntryNode = builder.getLastNode();
+  
+  // FIXME: Consolidate.
   CurrentStmt = S;
+  StateMgr.CurrentStmt = S;
   
   // Set up our simple checks.
   if (BatchAuditor)
@@ -296,7 +299,11 @@
   // NULL out these variables to cleanup.
   CleanedState = NULL;
   EntryNode = NULL;
-  CurrentStmt = NULL;
+
+  // FIXME: Consolidate.
+  StateMgr.CurrentStmt = 0;
+  CurrentStmt = 0;
+  
   Builder = NULL;
 }
 
@@ -1802,8 +1809,13 @@
             }
             else {
               nonlval::ConcreteInt X(BasicVals.getValue(0, Ex->getType()));
+#if 0            
               RVal Result = EvalBinOp(BinaryOperator::EQ, cast<NonLVal>(V), X);
               St = SetRVal(St, U, Result);
+#else
+              EvalBinOp(Dst, U, BinaryOperator::EQ, cast<NonLVal>(V), X, *I);
+              continue;
+#endif
             }
             
             break;
@@ -2226,6 +2238,31 @@
 }
 
 //===----------------------------------------------------------------------===//
+// Transfer-function Helpers.
+//===----------------------------------------------------------------------===//
+
+void GRExprEngine::EvalBinOp(ExplodedNodeSet<ValueState>& Dst, Expr* Ex,
+                             BinaryOperator::Opcode Op,
+                             NonLVal L, NonLVal R,
+                             ExplodedNode<ValueState>* Pred) {
+  
+  if (!R.isValid()) {
+    MakeNode(Dst, Ex, Pred, SetRVal(GetState(Pred), Ex, R));
+    return;
+  }
+  
+  assert (Builder && "GRStmtNodeBuilder must be defined.");    
+  unsigned size = Dst.size();
+  SaveOr OldHasGen(Builder->HasGeneratedNode);
+  
+  TF->EvalBinOpNN(Dst, *this, *Builder, Op, Ex, L, R, Pred);
+  
+  if (!Builder->BuildSinks && Dst.size() == size &&
+      !Builder->HasGeneratedNode)
+    MakeNode(Dst, Ex, Pred, GetState(Pred));
+}
+
+//===----------------------------------------------------------------------===//
 // "Assume" logic.
 //===----------------------------------------------------------------------===//
 

Modified: cfe/trunk/lib/Analysis/GRTransferFuncs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRTransferFuncs.cpp?rev=53739&r1=53738&r2=53739&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/GRTransferFuncs.cpp (original)
+++ cfe/trunk/lib/Analysis/GRTransferFuncs.cpp Thu Jul 17 16:27:31 2008
@@ -37,3 +37,18 @@
     Builder.MakeNode(Dst, E, Pred,
                 Eng.getStateManager().SetRVal(St, cast<LVal>(TargetLV), Val));    
 }
+
+void GRTransferFuncs::EvalBinOpNN(ExplodedNodeSet<ValueState>& Dst,
+                                  GRExprEngine& Engine,
+                                  GRStmtNodeBuilder<ValueState>& Builder,
+                                  BinaryOperator::Opcode Op,
+                                  Expr* Ex,
+                                  NonLVal L, NonLVal R,
+                                  ExplodedNode<ValueState>* Pred) {
+
+  ValueStateManager& StateMgr = Engine.getStateManager();
+  const ValueState* St = Builder.GetState(Pred);
+  
+  RVal Result = EvalBinOp(Engine, Op, L, R);
+  Builder.MakeNode(Dst, Ex, Pred, StateMgr.SetRVal(St, Ex, Result));
+}





More information about the cfe-commits mailing list