From 91e82dd47734ecd8a190a0e10b2283bae34319ef Mon Sep 17 00:00:00 2001 From: John McCall Date: Fri, 5 Aug 2011 00:14:38 +0000 Subject: [PATCH] The continue label in an ARC for-in loop should not involve releasing the collection. llvm-svn: 136949 --- clang/lib/CodeGen/CGObjC.cpp | 5 ++++- clang/test/CodeGenObjC/arc-foreach.m | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp index a51a8705f48b..944a0bd2a2c2 100644 --- a/clang/lib/CodeGen/CGObjC.cpp +++ b/clang/lib/CodeGen/CGObjC.cpp @@ -995,7 +995,6 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S){ variable = EmitAutoVarAlloca(*cast(SD->getSingleDecl())); JumpDest LoopEnd = getJumpDestInCurrentScope("forcoll.end"); - JumpDest AfterBody = getJumpDestInCurrentScope("forcoll.next"); // Fast enumeration state. QualType StateTy = getContext().getObjCFastEnumerationStateType(); @@ -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; diff --git a/clang/test/CodeGenObjC/arc-foreach.m b/clang/test/CodeGenObjC/arc-foreach.m index c5593ffb70ed..cfd0c0de6849 100644 --- a/clang/test/CodeGenObjC/arc-foreach.m +++ b/clang/test/CodeGenObjC/arc-foreach.m @@ -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]] +}