// RUN: // RUN: FileCheck -check-prefix LP64 --input-file=// rdar://9503326
// rdar://9606600
extern void use(id);
extern void use_block(void (^)(void));
struct NSFastEnumerationState;
@interface NSArray
- (unsigned long) countByEnumeratingWithState: (struct NSFastEnumerationState*) state
objects: (id*) buffer
count: (unsigned long) bufferSize;
@end;
void test0(NSArray *array) {
// 'x' should be initialized without a retain.
// We should actually do a non-constant capture, and that
// capture should require a retain.
for (id x in array) {
use_block(^{ use(x); });
}
}
// CHECK-LP64: define void @test0(
// CHECK-LP64: [[ARRAY:// CHECK-LP64-NEXT: [[X:// CHECK-LP64-NEXT: [[STATE:// CHECK-LP64-NEXT: [[BUFFER:// CHECK-LP64-NEXT: [[BLOCK:
// Initialize 'array'.
// CHECK-LP64-NEXT: [[T0:// CHECK-LP64-NEXT: [[T1:// CHECK-LP64-NEXT: [[T2:// CHECK-LP64-NEXT: store [[ARRAY_T]]* [[T2]], [[ARRAY_T]]** [[ARRAY]], align 8
// Initialize the fast enumaration state.
// CHECK-LP64-NEXT: [[T0:// CHECK-LP64-NEXT: call void @llvm.memset.p0i8.i64(i8* [[T0]], i8 0, i64 64, i32 8, i1 false)
// Evaluate the collection expression and retain.
// CHECK-LP64-NEXT: [[T0:// CHECK-LP64-NEXT: [[T1:// CHECK-LP64-NEXT: [[T2:// CHECK-LP64-NEXT: [[SAVED_ARRAY:
// Call the enumeration method.
// CHECK-LP64-NEXT: [[T0:// CHECK-LP64-NEXT: [[T1:// CHECK-LP64-NEXT: [[SIZE:
// Check for a nonzero result.
// CHECK-LP64-NEXT: [[T0:// CHECK-LP64-NEXT: br i1 [[T0]]
// CHECK-LP64: [[T0:// CHECK-LP64-NEXT: [[T1:// CHECK-LP64-NEXT: [[T2:// CHECK-LP64-NEXT: [[T3:// CHECK-LP64-NEXT: store i8* [[T3]], i8** [[X]]
// CHECK-LP64: [[D0:// CHECK-LP64: [[T0:// CHECK-LP64-NEXT: [[T1:// CHECK-LP64-NEXT: [[T2:// CHECK-LP64-NEXT: store i8* [[T2]], i8** [[T0]]
// CHECK-LP64-NEXT: [[T1:// CHECK-LP64: call void @use_block(
// CHECK-LP64-NEXT: call void @objc_storeStrong(i8** [[D0]], i8* null)
// CHECK-LP64: [[T0:// CHECK-LP64-NEXT: [[T1:// CHECK-LP64-NEXT: [[SIZE:
// Release the array.
// CHECK-LP64: [[T0:// CHECK-LP64-NEXT: call void @objc_release(i8* [[T0]])
// Destroy 'array'.
// CHECK-LP64: [[T0:// CHECK-LP64-NEXT: call void @objc_storeStrong(i8** [[T0]], i8* null)
// CHECK-LP64-NEXT: ret void
// CHECK-LP64: define internal void @__test0_block_invoke
// CHECK-LP64: [[BLOCK:// CHECK-LP64-NEXT: [[T0:// CHECK-LP64-NEXT: [[T2:// CHECK-LP64-NEXT: call void @use(i8* [[T2]])
void test1(NSArray *array) {
for (__weak id x in array) {
use_block(^{ use(x); });
}
}
// CHECK-LP64: define void @test1(
// CHECK-LP64: alloca [[ARRAY_T:// CHECK-LP64-NEXT: [[X:// CHECK-LP64-NEXT: [[STATE:// CHECK-LP64-NEXT: alloca [16 x i8*], align 8
// CHECK-LP64-NEXT: [[BLOCK:
// CHECK-LP64: [[T0:// CHECK-LP64-NEXT: [[T1:// CHECK-LP64-NEXT: [[T2:// CHECK-LP64-NEXT: [[T3:// CHECK-LP64-NEXT: call i8* @objc_initWeak(i8** [[X]], i8* [[T3]])
// CHECK-LP64: [[D0:// CHECK-LP64: [[T0:// CHECK-LP64-NEXT: [[T1:// CHECK-LP64-NEXT: call i8* @objc_initWeak(i8** [[T0]], i8* [[T1]])
// CHECK-LP64-NEXT: [[T1:// CHECK-LP64: call void @use_block
// CHECK-LP64-NEXT: call void @objc_destroyWeak(i8** [[D0]])
// CHECK-LP64-NEXT: call void @objc_destroyWeak(i8** [[X]])
// rdar://problem/9817306
@interface Test2
- (NSArray *) array;
@end
void test2(Test2 *a) {
for (id x in a.array) {
use(x);
}
}
// CHECK-LP64: define void @test2(
// CHECK-LP64: [[T0:// CHECK-LP64-NEXT: [[T1:// CHECK-LP64-NEXT: [[T2:// CHECK-LP64-NEXT: [[COLL:
// Make sure it's not immediately released before starting the iteration.
// CHECK-LP64-NEXT: load i8** @"\01L_OBJC_SELECTOR_REFERENCES_
// CHECK-LP64-NEXT: [[T0:// CHECK-LP64-NEXT: @objc_msgSend
// This bitcast is for the mutation check.
// CHECK-LP64: [[T0:// CHECK-LP64-NEXT: @objc_enumerationMutation
// This bitcast is for the 'next' message send.
// CHECK-LP64: [[T0:// CHECK-LP64-NEXT: @objc_msgSend
// This bitcast is for the final release.
// CHECK-LP64: [[T0:// 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: // CHECK-LP64-NEXT: [[X: // CHECK-LP64: [[T0: // CHECK-LP64-NEXT: [[T1: // CHECK-LP64-NEXT: br i1 [[T1]],
// CHECK-LP64: br label [[L: // CHECK-LP64: [[T0: // CHECK-LP64-NEXT: call void @use(i8* [[T0]])
// CHECK-LP64-NEXT: br label [[L]]
}