Skip to content

Commit

Permalink
The continue label in an ARC for-in loop should not involve
Browse files Browse the repository at this point in the history
releasing the collection.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136949 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
rjmccall committed Aug 5, 2011
1 parent ace5e76 commit 4b302d3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/CodeGen/CGObjC.cpp
Expand Up @@ -995,7 +995,6 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S){
variable = EmitAutoVarAlloca(*cast<VarDecl>(SD->getSingleDecl()));

JumpDest LoopEnd = getJumpDestInCurrentScope("forcoll.end");
JumpDest AfterBody = getJumpDestInCurrentScope("forcoll.next");

// Fast enumeration state.
QualType StateTy = getContext().getObjCFastEnumerationStateType();
Expand Down Expand Up @@ -1031,6 +1030,10 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S){
Collection = EmitScalarExpr(S.getCollection());
}

// The 'continue' label needs to appear within the cleanup for the
// collection object.
JumpDest AfterBody = getJumpDestInCurrentScope("forcoll.next");

// Send it our message:
CallArgList Args;

Expand Down
21 changes: 21 additions & 0 deletions test/CodeGenObjC/arc-foreach.m
Expand Up @@ -148,3 +148,24 @@ void test2(Test2 *a) {
// This bitcast is for the final release.
// CHECK-LP64: [[T0:%.*]] = bitcast [[ARRAY_T]]* [[COLL]] to i8*
// CHECK-LP64-NEXT: call void @objc_release(i8* [[T0]])


// Check that the 'continue' label is positioned appropriately
// relative to the collection clenaup.
void test3(NSArray *array) {
for (id x in array) {
if (!x) continue;
use(x);
}

// CHECK-LP64: define void @test3(
// CHECK-LP64: [[ARRAY:%.*]] = alloca [[ARRAY_T]]*, align 8
// CHECK-LP64-NEXT: [[X:%.*]] = alloca i8*, align 8
// CHECK-LP64: [[T0:%.*]] = load i8** [[X]], align 8
// CHECK-LP64-NEXT: [[T1:%.*]] = icmp ne i8* [[T0]], null
// CHECK-LP64-NEXT: br i1 [[T1]],
// CHECK-LP64: br label [[L:%[^ ]+]]
// CHECK-LP64: [[T0:%.*]] = load i8** [[X]], align 8
// CHECK-LP64-NEXT: call void @use(i8* [[T0]])
// CHECK-LP64-NEXT: br label [[L]]
}

0 comments on commit 4b302d3

Please sign in to comment.