[cfe-commits] r47184 - /cfe/trunk/Analysis/GRExprEngine.cpp

Ted Kremenek kremenek at apple.com
Fri Feb 15 14:29:00 PST 2008


Author: kremenek
Date: Fri Feb 15 16:29:00 2008
New Revision: 47184

URL: http://llvm.org/viewvc/llvm-project?rev=47184&view=rev
Log:
Added transfer function support for conditional branches with a NULL condition (e.g., "for(;;)").
Fixed bug in transfer function for compound assignment operators when both operands where variables but had a non-pointer type (we fired an assertion).

Modified:
    cfe/trunk/Analysis/GRExprEngine.cpp

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

==============================================================================
--- cfe/trunk/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/Analysis/GRExprEngine.cpp Fri Feb 15 16:29:00 2008
@@ -75,6 +75,21 @@
   // Remove old bindings for subexpressions.
   StateTy PrevState = StateMgr.RemoveSubExprBindings(builder.getState());
   
+  // 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;
+  }
+  
   RValue V = GetValue(PrevState, Condition);
   
   switch (V.getBaseKind()) {
@@ -98,10 +113,9 @@
       return;
     }      
   }
-
+  
   // Get the current block counter.
   GRBlockCounter BC = builder.getBlockCounter();
-    
   unsigned BlockID = builder.getTargetBlock(true)->getBlockID();
   unsigned NumVisited = BC.getNumVisited(BlockID);
   
@@ -708,11 +722,22 @@
             const NonLValue& R2 = cast<NonLValue>(V2);
             Result = EvalBinaryOp(ValMgr, Op, L1, R2);
           }
-          else if (isa<LValue>(V2)) {          // LValue comparison.
+          else if (isa<LValue>(V2)) {
             const LValue& L2 = cast<LValue>(V2);
-            Result = EvalBinaryOp(ValMgr, Op, L1, L2);
+            
+            if (B->getRHS()->getType()->isPointerType()) {
+              // LValue comparison.
+              Result = EvalBinaryOp(ValMgr, Op, L1, L2);
+            }
+            else {
+              // An operation between two variables of a non-lvalue type.
+              Result =
+                EvalBinaryOp(ValMgr, Op,
+                             cast<NonLValue>(GetValue(N1->getState(), L1)),
+                             cast<NonLValue>(GetValue(N2->getState(), L2)));
+            }
           }
-          else { // Any operation between two Non-LValues.
+          else { // Any other operation between two Non-LValues.
             const NonLValue& R1 = cast<NonLValue>(GetValue(N1->getState(), L1));
             const NonLValue& R2 = cast<NonLValue>(V2);
             Result = EvalBinaryOp(ValMgr, Op, R1, R2);





More information about the cfe-commits mailing list