1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fblocks -fobjc-arc -emit-llvm -o - %s | FileCheck %s
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.
15 __attribute__((objc_root_class))
16 @interface NSObject <NSObject>
19 @interface NSString : NSObject <NSCopying>
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;
31 NSString *getFirstObjectProp(NSMutableArray<NSString *> *array) {
32 return array.firstObject;
35 NSString *getFirstObjectMethod(NSMutableArray<NSString *> *array) {
36 return [array firstObject];
39 void addObject(NSMutableArray<NSString *> *array, NSString *obj) {
40 [array addObject: obj];
43 int compareStrings(NSString *x, NSString *y) { return 0; }
44 int compareBlocks(NSString * (^x)(NSString *),
45 NSString * (^y)(NSString *)) { return 0; }
47 void sortTest(NSMutableArray<NSString *> *array,
48 NSMutableArray<NSString * (^)(NSString *)> *array2) {
49 [array sortWithFunction: &compareStrings];
50 [array2 sortWithFunction: &compareBlocks];
53 void getObjectsTest(NSMutableArray<NSString *> *array) {
54 NSString * __strong *objects;
56 [array getObjects: objects length: &length];
59 void printMe(NSString *name) { }
61 // CHECK-LABEL: define{{.*}} void @blockTest
62 void blockTest(NSMutableArray<void (^)(void)> *array, NSString *name) {
63 // CHECK-NOT: ret void
64 // CHECK: call ptr @llvm.objc.retainBlock
65 [array addObject: ^ { printMe(name); }];
66 // CHECK-NOT: ret void
67 array[0] = ^ { printMe(name); };
68 // CHECK: call ptr @llvm.objc.retainBlock
72 // CHECK-LABEL: define internal void @"\01-[Derived setDest:]
73 // CHECK: %[[SELFADDR:.*]] = alloca ptr
74 // CHECK: %[[AADDR:a.addr]] = alloca ptr
75 // CHECK: %[[V2:.*]] = load ptr, ptr %[[AADDR]]
76 // CHECK: %[[V3:.*]] = load ptr, ptr %[[SELFADDR]]
77 // CHECK: %[[IVAR:.*]] = load i64, ptr @"OBJC_IVAR_$_Base._destination"
78 // CHECK: %[[ADDPTR:.*]] = getelementptr inbounds i8, ptr %[[V3]], i64 %[[IVAR]]
79 // CHECK: call void @llvm.objc.storeStrong(ptr %[[ADDPTR]], ptr %[[V2]])
81 @interface Base<DestType> : NSObject {
82 DestType _destination;
86 @interface Derived : Base<NSObject *>
87 - (void)setDest:(NSObject *)a;
90 @implementation Derived
91 - (void)setDest:(NSObject *)a {
96 // CHECK-LABEL: define internal void @"\01-[C0 foo1]"(
97 // CHECK: {{.*}} = alloca
98 // CHECK: {{.*}} = alloca
99 // CHECK: %[[D:.*]] = alloca ptr
100 // CHECK: %[[TEMP:.*]] = alloca ptr
101 // CHECK: %[[V4:.*]] = load ptr, ptr %[[D]]
102 // CHECK: store ptr %[[V4]], ptr %[[TEMP]]
103 // CHECK: call void @objc_msgSend(ptr noundef %{{.*}}, ptr noundef %{{.*}}, ptr noundef %[[TEMP]])
105 @interface P0<ObjectType> : NSObject
106 - (void)m0:(ObjectType *)first;
109 @interface C0 : NSObject