]> granicus.if.org Git - clang/commitdiff
Shore up transfer function for ObjCForCollectionStmt.
authorTed Kremenek <kremenek@apple.com>
Wed, 12 Nov 2008 21:12:46 +0000 (21:12 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 12 Nov 2008 21:12:46 +0000 (21:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59162 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/GRExprEngine.cpp

index 2fa163ad230ea8f399fadeeaf08bba91d8a804c5..9e389e8b1211ea28ba615ae3cd359fb81cd9f96b 100644 (file)
@@ -1383,12 +1383,12 @@ void GRExprEngine::VisitObjCForCollectionStmt(ObjCForCollectionStmt* S,
   
   Stmt* elem = S->getElement();  
   VarDecl* ElemD;
-  bool bindDecl = false;
+  bool newDecl = false;
     
   if (DeclStmt* DS = dyn_cast<DeclStmt>(elem)) {
     ElemD = cast<VarDecl>(DS->getSolitaryDecl());
     assert (ElemD->getInit() == 0);
-    bindDecl = true;
+    newDecl = true;
   }
   else
     ElemD = cast<VarDecl>(cast<DeclRefExpr>(elem)->getDecl());
@@ -1408,18 +1408,26 @@ void GRExprEngine::VisitObjCForCollectionStmt(ObjCForCollectionStmt* S,
   unsigned Count = Builder->getCurrentBlockCount();
   loc::SymbolVal SymV(SymMgr.getConjuredSymbol(elem, ElemTy, Count));
   
-  if (bindDecl)
+  if (newDecl)
     hasElems = hasElems.BindDecl(ElemD, &SymV, Count);
   else
     hasElems = hasElems.BindLoc(hasElems.GetLValue(ElemD), SymV);
   
-  
   // Handle the case where the container has no elements.
-  
-    
-  
-  
-  
+  SVal FalseV = NonLoc::MakeVal(getBasicVals(), 0, IntTy);
+  GRStateRef noElems = state.BindExpr(S, FalseV);
+
+  if (!newDecl) {
+    // We only need to bind nil to an existing variable, since out of the
+    // loop the VarDecl won't exist and there will be no chance to get it's
+    // address via the '&' operator.
+    SVal nilV = loc::ConcreteInt(getBasicVals().getValue(0, ElemTy));
+    noElems.BindLoc(noElems.GetLValue(ElemD), nilV);
+  }
+
+  // Create the new nodes.
+  MakeNode(Dst, S, Pred, hasElems);
+  MakeNode(Dst, S, Pred, noElems);
 }
 
 //===----------------------------------------------------------------------===//