blob: 1d8e9a259934b5b0e88bfa4b92c2299826082d6c [file] [log] [blame]
Douglas Gregore83b9562015-07-07 03:57:53 +00001// 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@end
28
29NSString *getFirstObjectProp(NSMutableArray<NSString *> *array) {
30 return array.firstObject;
31}
32
33NSString *getFirstObjectMethod(NSMutableArray<NSString *> *array) {
34 return [array firstObject];
35}
36
37void addObject(NSMutableArray<NSString *> *array, NSString *obj) {
38 [array addObject: obj];
39}
40
41int compareStrings(NSString *x, NSString *y) { return 0; }
42int compareBlocks(NSString * (^x)(NSString *),
43 NSString * (^y)(NSString *)) { return 0; }
44
45void sortTest(NSMutableArray<NSString *> *array,
46 NSMutableArray<NSString * (^)(NSString *)> *array2) {
47 [array sortWithFunction: &compareStrings];
48 [array2 sortWithFunction: &compareBlocks];
49}
50
51void getObjectsTest(NSMutableArray<NSString *> *array) {
52 NSString * __strong *objects;
53 unsigned length;
54 [array getObjects: objects length: &length];
55}
56
57void printMe(NSString *name) { }
58
59// CHECK-LABEL: define void @blockTest
60void blockTest(NSMutableArray<void (^)(void)> *array, NSString *name) {
61 // CHECK: call i8* @objc_retainBlock
62 [array addObject: ^ { printMe(name); }];
63}