From 3b4e1d5cc62a2c29871cd2c7262143a3a5b30d04 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 11 Nov 2008 19:40:47 +0000 Subject: [PATCH] Accesses to a collection within a fast enumeration 'for' statement constitute a 'use'. llvm-svn: 59075 --- clang/lib/Analysis/LiveVariables.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/clang/lib/Analysis/LiveVariables.cpp b/clang/lib/Analysis/LiveVariables.cpp index 07fda99166c4..83a0115429a4 100644 --- a/clang/lib/Analysis/LiveVariables.cpp +++ b/clang/lib/Analysis/LiveVariables.cpp @@ -176,18 +176,24 @@ void TransferFuncs::VisitBinaryOperator(BinaryOperator* B) { else VisitStmt(B); } -void TransferFuncs::VisitObjCForCollectionStmt(ObjCForCollectionStmt* S) { - Stmt* Element = S->getElement(); - - if (DeclStmt* DS = dyn_cast(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(Element); - LiveState(cast(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(Element)) + VD = cast(DS->getSolitaryDecl()); + else { + DR = cast(Element); + VD = cast(DR->getDecl()); + } + + LiveState(VD, AD) = Dead; + if (AD.Observer && DR) { AD.Observer->ObserverKill(DR); } }