Accesses to a collection within a fast enumeration 'for' statement constitute a 'use'.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59075 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/LiveVariables.cpp b/lib/Analysis/LiveVariables.cpp
index 07fda99..83a0115 100644
--- a/lib/Analysis/LiveVariables.cpp
+++ b/lib/Analysis/LiveVariables.cpp
@@ -176,18 +176,24 @@
   else VisitStmt(B);
 }
 
-void TransferFuncs::VisitObjCForCollectionStmt(ObjCForCollectionStmt* S) {
-  Stmt* Element = S->getElement();
-  
-  if (DeclStmt* DS = dyn_cast<DeclStmt>(Element)) {
-    VisitDeclStmt(DS);
-    return;
-  }
+void TransferFuncs::VisitObjCForCollectionStmt(ObjCForCollectionStmt* S) {  
+  // This represents a 'use' of the collection.
+  Visit(S->getCollection());
   
   // This represents a 'kill' for the variable.
-  DeclRefExpr* DR = cast<DeclRefExpr>(Element);
-  LiveState(cast<VarDecl>(DR->getDecl()), AD) = Dead;
-  if (AD.Observer) { AD.Observer->ObserverKill(DR); }
+  Stmt* Element = S->getElement();
+  DeclRefExpr *DR;
+  VarDecl* VD = 0;
+  
+  if (DeclStmt* DS = dyn_cast<DeclStmt>(Element))
+    VD = cast<VarDecl>(DS->getSolitaryDecl());
+  else {
+    DR = cast<DeclRefExpr>(Element);
+    VD = cast<VarDecl>(DR->getDecl());
+  }
+
+  LiveState(VD, AD) = Dead;
+  if (AD.Observer && DR) { AD.Observer->ObserverKill(DR); }
 }