1// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fblocks -fobjc-arc -emit-llvm -o - %s | FileCheck %s
2
3// Parameterized classes have no effect on code generation; this test
4// mainly verifies that CodeGen doesn't assert when substituted types
5// in uses of methods don't line up exactly with the parameterized
6// types in the method declarations due to type erasure. "Not crash"
7// is the only interesting criteria here.
8
9@protocol NSObject
10@end
11
12@protocol NSCopying
13@end
14
15__attribute__((objc_root_class))
16@interface NSObject <NSObject>
17@end
18
19@interface NSString : NSObject <NSCopying>
20@end
21
22@interface NSMutableArray<T> : NSObject <NSCopying>
23@property (copy,nonatomic) T firstObject;
24- (void)addObject:(T)object;
25- (void)sortWithFunction:(int (*)(T, T))function;
26- (void)getObjects:(T __strong *)objects length:(unsigned*)length;
27- (T)objectAtIndexedSubscript:(unsigned)index;
28- (void)setObject:(T)object atIndexedSubscript:(unsigned)index;
29@end
30
31NSString *getFirstObjectProp(NSMutableArray<NSString *> *array) {
32  return array.firstObject;
33}
34
35NSString *getFirstObjectMethod(NSMutableArray<NSString *> *array) {
36  return [array firstObject];
37}
38
39void addObject(NSMutableArray<NSString *> *array, NSString *obj) {
40  [array addObject: obj];
41}
42
43int compareStrings(NSString *x, NSString *y) { return 0; }
44int compareBlocks(NSString * (^x)(NSString *),
45                  NSString * (^y)(NSString *)) { return 0; }
46
47void sortTest(NSMutableArray<NSString *> *array,
48              NSMutableArray<NSString * (^)(NSString *)> *array2) {
49  [array sortWithFunction: &compareStrings];
50  [array2 sortWithFunction: &compareBlocks];
51}
52
53void getObjectsTest(NSMutableArray<NSString *> *array) {
54  NSString * __strong *objects;
55  unsigned length;
56  [array getObjects: objects length: &length];
57}
58
59void printMe(NSString *name) { }
60
61// CHECK-LABEL: define void @blockTest
62void blockTest(NSMutableArray<void (^)(void)> *array, NSString *name) {
63  // CHECK-NOT: ret void
64  // CHECK: call i8* @objc_retainBlock
65  [array addObject: ^ { printMe(name); }];
66  // CHECK-NOT: ret void
67  array[0] = ^ { printMe(name); };
68  // CHECK: call i8* @objc_retainBlock
69  // CHECK: ret void
70}
71