diff options
author | John McCall <rjmccall@apple.com> | 2011-07-27 01:07:15 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2011-07-27 01:07:15 +0000 |
commit | 990567cb60e8530ba01b41d4e056e32b44b95ec0 (patch) | |
tree | 8f85e629bf057a38f2f2cf4f4e744c50a6f1fb1f /lib/Parse/ParseStmt.cpp | |
parent | dfb6ae1d8d114772bd91b7079c7e4bf4b517e63c (diff) |
Clean up the analysis of the collection operand to ObjC
for-in statements; specifically, make sure to close over any
temporaries or cleanups it might require. In ARC, this has
implications for the lifetime of the collection, so emit it
with a retain and release it upon exit from the loop.
rdar://problem/9817306
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136204 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/ParseStmt.cpp')
-rw-r--r-- | lib/Parse/ParseStmt.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index 622c8ea905..b34e4f8277 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -1405,13 +1405,22 @@ StmtResult Parser::ParseForStatement(ParsedAttributes &attrs) { // statememt before parsing the body, in order to be able to deduce the type // of an auto-typed loop variable. StmtResult ForRangeStmt; - if (ForRange) + if (ForRange) { ForRangeStmt = Actions.ActOnCXXForRangeStmt(ForLoc, LParenLoc, FirstPart.take(), ForRangeInit.ColonLoc, ForRangeInit.RangeExpr.get(), RParenLoc); + + // Similarly, we need to do the semantic analysis for a for-range + // statement immediately in order to close over temporaries correctly. + } else if (ForEach) { + if (!Collection.isInvalid()) + Collection = + Actions.ActOnObjCForCollectionOperand(ForLoc, Collection.take()); + } + // C99 6.8.5p5 - In C99, the body of the if statement is a scope, even if // there is no compound stmt. C90 does not have this clause. We only do this // if the body isn't a compound statement to avoid push/pop in common cases. @@ -1439,8 +1448,6 @@ StmtResult Parser::ParseForStatement(ParsedAttributes &attrs) { return StmtError(); if (ForEach) - // FIXME: It isn't clear how to communicate the late destruction of - // C++ temporaries used to create the collection. return Actions.ActOnObjCForCollectionStmt(ForLoc, LParenLoc, FirstPart.take(), Collection.take(), RParenLoc, |