122 lines · plain
1// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fblocks -fobjc-arc -emit-llvm -o - %s | FileCheck %s2 3// Parameterized classes have no effect on code generation; this test4// mainly verifies that CodeGen doesn't assert when substituted types5// in uses of methods don't line up exactly with the parameterized6// types in the method declarations due to type erasure. "Not crash"7// is the only interesting criteria here.8 9@protocol NSObject10@end11 12@protocol NSCopying13@end14 15__attribute__((objc_root_class))16@interface NSObject <NSObject>17@end18 19@interface NSString : NSObject <NSCopying>20@end21 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@end30 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 @blockTest62void blockTest(NSMutableArray<void (^)(void)> *array, NSString *name) {63 // CHECK-NOT: ret void64 // CHECK: call ptr @llvm.objc.retainBlock65 [array addObject: ^ { printMe(name); }];66 // CHECK-NOT: ret void67 array[0] = ^ { printMe(name); };68 // CHECK: call ptr @llvm.objc.retainBlock69 // CHECK: ret void70}71 72// CHECK-LABEL: define internal void @"\01-[Derived setDest:]73// CHECK: %[[SELFADDR:.*]] = alloca ptr74// CHECK: %[[AADDR:a.addr]] = alloca ptr75// 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]])80 81@interface Base<DestType> : NSObject {82 DestType _destination;83}84@end85 86@interface Derived : Base<NSObject *>87- (void)setDest:(NSObject *)a;88@end89 90@implementation Derived91- (void)setDest:(NSObject *)a {92 _destination = a;93}94@end95 96// CHECK-LABEL: define internal void @"\01-[C0 foo1]"(97// CHECK: {{.*}} = alloca98// CHECK: {{.*}} = alloca99// CHECK: %[[D:.*]] = alloca ptr100// CHECK: %[[TEMP:.*]] = alloca ptr101// 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]])104 105@interface P0<ObjectType> : NSObject106- (void)m0:(ObjectType *)first;107@end108 109@interface C0 : NSObject110-(void)foo1;111@end112 113@implementation C0 {114 P0<NSString *> *x;115}116 117-(void)foo1 {118 NSString *d;119 [x m0:&d];120}121@end122