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

Ted Kremenek kremenek at apple.com
Wed Feb 25 15:32:11 PST 2009


Author: kremenek
Date: Wed Feb 25 17:32:10 2009
New Revision: 65486

URL: http://llvm.org/viewvc/llvm-project?rev=65486&view=rev
Log:
Fix subtle bug in EvalEagerlyAssume: Check if the previous node was at the same statement.

Modified:
    cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h
    cfe/trunk/lib/Analysis/GRExprEngine.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=65486&r1=65485&r2=65486&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h Wed Feb 25 17:32:10 2009
@@ -618,7 +618,7 @@
   /// EvalEagerlyAssume - Given the nodes in 'Src', eagerly assume symbolic
   ///  expressions of the form 'x != 0' and generate new nodes (stored in Dst)
   ///  with those assumptions.
-  void EvalEagerlyAssume(NodeSet& Dst, NodeSet& Src);
+  void EvalEagerlyAssume(NodeSet& Dst, NodeSet& Src, Expr *Ex);
   
   SVal EvalCast(SVal X, QualType CastT) {
     if (X.isUnknownOrUndef())

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

==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngine.cpp Wed Feb 25 17:32:10 2009
@@ -266,7 +266,7 @@
       if (EagerlyAssume && (B->isRelationalOp() || B->isEqualityOp())) {
         NodeSet Tmp;
         VisitBinaryOperator(cast<BinaryOperator>(S), Pred, Tmp);
-        EvalEagerlyAssume(Dst, Tmp);        
+        EvalEagerlyAssume(Dst, Tmp, cast<Expr>(S));        
       }
       else
         VisitBinaryOperator(cast<BinaryOperator>(S), Pred, Dst);
@@ -1359,20 +1359,28 @@
 
 static std::pair<const void*,const void*> EagerlyAssumeTag(&EagerlyAssumeTag,0);
 
-void GRExprEngine::EvalEagerlyAssume(NodeSet &Dst, NodeSet &Src) {
+void GRExprEngine::EvalEagerlyAssume(NodeSet &Dst, NodeSet &Src, Expr *Ex) {
   for (NodeSet::iterator I=Src.begin(), E=Src.end(); I!=E; ++I) {
     NodeTy *Pred = *I;
-    Stmt *S = cast<PostStmt>(Pred->getLocation()).getStmt();
+    
+    // Test if the previous node was as the same expression.  This can happen
+    // when the expression fails to evaluate to anything meaningful and
+    // (as an optimization) we don't generate a node.
+    ProgramPoint P = Pred->getLocation();    
+    if (!isa<PostStmt>(P) || cast<PostStmt>(P).getStmt() != Ex) {
+      Dst.Add(Pred);      
+      continue;
+    }    
+
     const GRState* state = Pred->getState();    
-    SVal V = GetSVal(state, S);    
+    SVal V = GetSVal(state, Ex);    
     if (isa<nonloc::SymIntConstraintVal>(V)) {
       // First assume that the condition is true.
       bool isFeasible = false;
       const GRState *stateTrue = Assume(state, V, true, isFeasible);
       if (isFeasible) {
-        stateTrue = BindExpr(stateTrue, cast<Expr>(S),
-                             MakeConstantVal(1U, cast<Expr>(S)));        
-        Dst.Add(Builder->generateNode(PostStmtCustom(S, &EagerlyAssumeTag),
+        stateTrue = BindExpr(stateTrue, Ex, MakeConstantVal(1U, Ex));        
+        Dst.Add(Builder->generateNode(PostStmtCustom(Ex, &EagerlyAssumeTag),
                                       stateTrue, Pred));
       }
         
@@ -1380,9 +1388,8 @@
       isFeasible = false;
       const GRState *stateFalse = Assume(state, V, false, isFeasible);
       if (isFeasible) {
-        stateFalse = BindExpr(stateFalse, cast<Expr>(S),
-                              MakeConstantVal(0U, cast<Expr>(S)));
-        Dst.Add(Builder->generateNode(PostStmtCustom(S, &EagerlyAssumeTag),
+        stateFalse = BindExpr(stateFalse, Ex, MakeConstantVal(0U, Ex));
+        Dst.Add(Builder->generateNode(PostStmtCustom(Ex, &EagerlyAssumeTag),
                                       stateFalse, Pred));
       }
     }





More information about the cfe-commits mailing list