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

Ted Kremenek kremenek at apple.com
Fri Sep 19 18:50:34 PDT 2008


Author: kremenek
Date: Fri Sep 19 20:50:34 2008
New Revision: 56383

URL: http://llvm.org/viewvc/llvm-project?rev=56383&view=rev
Log:
Add PostStore, a new ProgramPoint to distinguish between 'stores' and other PostStmts.

GRExprEngine:
  Use PostStore in EvalStore.
  Use a second version of EvalStore in EvalBinaryOperator to associate the store with the expression on the LHS.

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

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=56383&r1=56382&r2=56383&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRCoreEngine.h Fri Sep 19 20:50:34 2008
@@ -179,7 +179,8 @@
 public:
   GRStmtNodeBuilder(GRStmtNodeBuilderImpl& nb, StateManagerTy& mgr) :
     NB(nb), Mgr(mgr), Auditor(0), PurgingDeadSymbols(false),
-    BuildSinks(false), HasGeneratedNode(false) {
+    BuildSinks(false), HasGeneratedNode(false),
+    PointKind(ProgramPoint::PostStmtKind) {
       
     CleanedState = getLastNode()->getState();
   }
@@ -192,24 +193,28 @@
     return static_cast<NodeTy*>(NB.getLastNode());
   }
   
-  NodeTy*
-  generateNode(Stmt* S, const StateTy* St, NodeTy* Pred,
-               ProgramPoint::Kind K = ProgramPoint::PostStmtKind) {
-
+  NodeTy* generateNode(Stmt* S, const StateTy* St, NodeTy* Pred,
+                       ProgramPoint::Kind K) {
     HasGeneratedNode = true;
     if (PurgingDeadSymbols) K = ProgramPoint::PostPurgeDeadSymbolsKind;      
     return static_cast<NodeTy*>(NB.generateNodeImpl(S, St, Pred, K));
   }
   
-  NodeTy*
-  generateNode(Stmt* S, const StateTy* St,
-               ProgramPoint::Kind K = ProgramPoint::PostStmtKind) {
-      
+  NodeTy* generateNode(Stmt* S, const StateTy* St, NodeTy* Pred) {
+    return generateNode(S, St, Pred, PointKind);
+  }
+  
+  NodeTy* generateNode(Stmt* S, const StateTy* St, ProgramPoint::Kind K) {
     HasGeneratedNode = true;
     if (PurgingDeadSymbols) K = ProgramPoint::PostPurgeDeadSymbolsKind;      
     return static_cast<NodeTy*>(NB.generateNodeImpl(S, St, K));
   }
   
+  NodeTy* generateNode(Stmt* S, const StateTy* St) {
+    return generateNode(S, St, PointKind);
+  }
+
+  
   GRBlockCounter getBlockCounter() const {
     return NB.getBlockCounter();
   }  
@@ -269,6 +274,7 @@
   bool PurgingDeadSymbols;
   bool BuildSinks;
   bool HasGeneratedNode;
+  ProgramPoint::Kind PointKind;
 };
   
 class GRBranchNodeBuilderImpl {

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=56383&r1=56382&r2=56383&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h Fri Sep 19 20:50:34 2008
@@ -618,6 +618,9 @@
   void EvalStore(NodeSet& Dst, Expr* E, NodeTy* Pred, const GRState* St,
                  RVal TargetLV, RVal Val);
   
+  void EvalStore(NodeSet& Dst, Expr* E, Expr* StoreE, NodeTy* Pred,
+                 const GRState* St, RVal TargetLV, RVal Val);
+  
   // FIXME: The "CheckOnly" option exists only because Array and Field
   //  loads aren't fully implemented.  Eventually this option will go away.
   

Modified: cfe/trunk/include/clang/Analysis/ProgramPoint.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/ProgramPoint.h?rev=56383&r1=56382&r2=56383&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/ProgramPoint.h (original)
+++ cfe/trunk/include/clang/Analysis/ProgramPoint.h Fri Sep 19 20:50:34 2008
@@ -26,8 +26,9 @@
 class ProgramPoint {
 public:
   enum Kind { BlockEdgeKind=0, BlockEntranceKind, BlockExitKind, 
-              // Keep the following three together and in this order.
-              PostStmtKind, PostLoadKind, PostPurgeDeadSymbolsKind };
+              // Keep the following four together and in this order.
+              PostStmtKind, PostLoadKind, PostStoreKind,
+              PostPurgeDeadSymbolsKind };
 
 private:
   std::pair<uintptr_t,uintptr_t> Data;
@@ -153,6 +154,15 @@
   }
 };
   
+class PostStore : public PostStmt {
+public:
+  PostStore(const Stmt* S) : PostStmt(S, PostLoadKind) {}
+  
+  static bool classof(const ProgramPoint* Location) {
+    return Location->getKind() == PostStoreKind;
+  }
+};
+  
 class PostPurgeDeadSymbols : public PostStmt {
 public:
   PostPurgeDeadSymbols(const Stmt* S) : PostStmt(S, PostPurgeDeadSymbolsKind) {}

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

==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngine.cpp Fri Sep 19 20:50:34 2008
@@ -928,9 +928,11 @@
   unsigned size = Dst.size();  
 
   SaveAndRestore<bool> OldSink(Builder->BuildSinks);
+  SaveAndRestore<ProgramPoint::Kind> OldSPointKind(Builder->PointKind);
   SaveOr OldHasGen(Builder->HasGeneratedNode);
 
   assert (!location.isUndef());
+  Builder->PointKind = ProgramPoint::PostStoreKind;
   
   getTF().EvalStore(Dst, *this, *Builder, Ex, Pred, St, location, Val);
   
@@ -973,6 +975,16 @@
                                                     Ex->getType())), K);  
 }
 
+void GRExprEngine::EvalStore(NodeSet& Dst, Expr* Ex, Expr* StoreE, NodeTy* Pred,
+                             const GRState* St, RVal location, RVal Val) {
+ 
+  NodeSet TmpDst;
+  EvalStore(TmpDst, StoreE, Pred, St, location, Val);
+
+  for (NodeSet::iterator I=TmpDst.begin(), E=TmpDst.end(); I!=E; ++I)
+    MakeNode(Dst, Ex, *I, (*I)->getState());
+}
+
 const GRState* GRExprEngine::EvalLocation(Expr* Ex, NodeTy* Pred,
                                              const GRState* St,
                                              RVal location, bool isLoad) {
@@ -2001,7 +2013,7 @@
           // Simulate the effects of a "store":  bind the value of the RHS
           // to the L-Value represented by the LHS.
           
-          EvalStore(Dst, B, *I2, SetRVal(St, B, RightV), LeftV, RightV);          
+          EvalStore(Dst, B, LHS, *I2, SetRVal(St, B, RightV), LeftV, RightV);          
           continue;
         }
           
@@ -2071,13 +2083,13 @@
 
         // Propagate undefined values (left-side).          
         if (V.isUndef()) {
-          EvalStore(Dst, B, *I3, SetRVal(St, B, V), location, V);
+          EvalStore(Dst, B, LHS, *I3, SetRVal(St, B, V), location, V);
           continue;
         }
         
         // Propagate unknown values (left and right-side).
         if (RightV.isUnknown() || V.isUnknown()) {
-          EvalStore(Dst, B, *I3, SetRVal(St, B, UnknownVal()), location,
+          EvalStore(Dst, B, LHS, *I3, SetRVal(St, B, UnknownVal()), location,
                     UnknownVal());
           continue;
         }
@@ -2102,11 +2114,9 @@
           if (CheckDivideZero(B, St, *I3, RightV))
             continue;
         }
-        else if (RightV.isUndef()) {
-            
-          // Propagate undefined values (right-side).
-          
-          EvalStore(Dst, B, *I3, SetRVal(St, B, RightV), location, RightV);
+        else if (RightV.isUndef()) {            
+          // Propagate undefined values (right-side).          
+          EvalStore(Dst, B, LHS, *I3, SetRVal(St, B, RightV), location, RightV);
           continue;
         }
       
@@ -2126,7 +2136,7 @@
           continue;
         }
  
-        EvalStore(Dst, B, *I3, SetRVal(St, B, Result), location, Result);
+        EvalStore(Dst, B, LHS, *I3, SetRVal(St, B, Result), location, Result);
       }
     }
   }





More information about the cfe-commits mailing list