1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
|
// RUN: %clang_cc1 -fobjc-runtime=macosx-10.10.0 -emit-llvm -o - %s -fno-objc-convert-messages-to-runtime-calls -fobjc-exceptions -fexceptions | FileCheck %s --check-prefix=MSGS
// RUN: %clang_cc1 -fobjc-runtime=macosx-10.10.0 -emit-llvm -o - %s -fobjc-exceptions -fexceptions | FileCheck %s --check-prefix=CALLS
// RUN: %clang_cc1 -fobjc-runtime=macosx-10.9.0 -emit-llvm -o - %s -fobjc-exceptions -fexceptions | FileCheck %s --check-prefix=MSGS
// RUN: %clang_cc1 -fobjc-runtime=macosx-fragile-10.10.0 -emit-llvm -o - %s -fobjc-exceptions -fexceptions | FileCheck %s --check-prefix=MSGS
// RUN: %clang_cc1 -fobjc-runtime=ios-8.0 -emit-llvm -o - %s -fobjc-exceptions -fexceptions | FileCheck %s --check-prefix=CALLS
// RUN: %clang_cc1 -fobjc-runtime=ios-7.0 -emit-llvm -o - %s -fobjc-exceptions -fexceptions | FileCheck %s --check-prefix=MSGS
// Note: This line below is for tvos for which the driver passes through to use the ios9.0 runtime.
// RUN: %clang_cc1 -fobjc-runtime=ios-9.0 -emit-llvm -o - %s -fobjc-exceptions -fexceptions | FileCheck %s --check-prefix=CALLS
// RUN: %clang_cc1 -fobjc-runtime=watchos-2.0 -emit-llvm -o - %s -fobjc-exceptions -fexceptions | FileCheck %s --check-prefix=CALLS
#define nil (id)0
@interface NSObject
+ (id)alloc;
+ (id)allocWithZone:(void*)zone;
+ (id)alloc2;
- (id)retain;
- (void)release;
- (id)autorelease;
@end
// CHECK-LABEL: define {{.*}}void @test1
void test1(id x) {
// MSGS: {{call.*@objc_msgSend}}
// MSGS: {{call.*@objc_msgSend}}
// MSGS: {{call.*@objc_msgSend}}
// MSGS: {{call.*@objc_msgSend}}
// MSGS: {{call.*@objc_msgSend}}
// CALLS: {{call.*@objc_alloc}}
// CALLS: {{call.*@objc_allocWithZone}}
// CALLS: {{call.*@objc_retain}}
// CALLS: {{call.*@objc_release}}
// CALLS: {{call.*@objc_autorelease}}
[NSObject alloc];
[NSObject allocWithZone:nil];
[x retain];
[x release];
[x autorelease];
}
// CHECK-LABEL: define {{.*}}void @check_invoke
void check_invoke() {
// MSGS: {{invoke.*@objc_msgSend}}
// MSGS: {{invoke.*@objc_msgSend}}
// CALLS: {{invoke.*@objc_alloc}}
// CALLS: {{invoke.*@objc_allocWithZone}}
@try {
[NSObject alloc];
[NSObject allocWithZone:nil];
} @catch (...) {
}
}
// CHECK-LABEL: define {{.*}}void @test2
void test2(void* x) {
// MSGS: {{call.*@objc_msgSend}}
// MSGS: {{call.*@objc_msgSend}}
// MSGS: {{call.*@objc_msgSend}}
// CALLS: {{call.*@objc_msgSend}}
// CALLS: {{call.*@objc_msgSend}}
// CALLS: {{call.*@objc_msgSend}}
[NSObject alloc2];
[NSObject allocWithZone:(void*)-1];
[NSObject allocWithZone:x];
}
@class A;
@interface B
+ (A*) alloc;
+ (A*) allocWithZone:(void*)zone;
- (A*) alloc;
- (A*) allocWithZone:(void*)zone;
- (A*) retain;
- (A*) autorelease;
@end
// Make sure we get a bitcast on the return type as the
// call will return i8* which we have to cast to A*
// CHECK-LABEL: define {{.*}}void @test_alloc_class_ptr
A* test_alloc_class_ptr() {
// CALLS: {{call.*@objc_alloc}}
// CALLS-NEXT: bitcast i8*
// CALLS-NEXT: ret
return [B alloc];
}
// Make sure we get a bitcast on the return type as the
// call will return i8* which we have to cast to A*
// CHECK-LABEL: define {{.*}}void @test_alloc_class_ptr
A* test_allocWithZone_class_ptr() {
// CALLS: {{call.*@objc_allocWithZone}}
// CALLS-NEXT: bitcast i8*
// CALLS-NEXT: ret
return [B allocWithZone:nil];
}
// Only call objc_alloc on a Class, not an instance
// CHECK-LABEL: define {{.*}}void @test_alloc_instance
void test_alloc_instance(A *a) {
// CALLS: {{call.*@objc_alloc}}
// CALLS: {{call.*@objc_allocWithZone}}
// CALLS: {{call.*@objc_msgSend}}
// CALLS: {{call.*@objc_msgSend}}
[A alloc];
[A allocWithZone:nil];
[a alloc];
[a allocWithZone:nil];
}
// Make sure we get a bitcast on the return type as the
// call will return i8* which we have to cast to A*
// CHECK-LABEL: define {{.*}}void @test_retain_class_ptr
A* test_retain_class_ptr(B *b) {
// CALLS: {{call.*@objc_retain}}
// CALLS-NEXT: bitcast i8*
// CALLS-NEXT: ret
return [b retain];
}
// Make sure we get a bitcast on the return type as the
// call will return i8* which we have to cast to A*
// CHECK-LABEL: define {{.*}}void @test_autorelease_class_ptr
A* test_autorelease_class_ptr(B *b) {
// CALLS: {{call.*@objc_autorelease}}
// CALLS-NEXT: bitcast i8*
// CALLS-NEXT: ret
return [b autorelease];
}
@interface C
+ (id)allocWithZone:(int)intArg;
- (float) retain;
@end
// Make sure we only accept pointer types
// CHECK-LABEL: define {{.*}}void @test_allocWithZone_int
C* test_allocWithZone_int() {
// MSGS: {{call.*@objc_msgSend}}
// CALLS: {{call.*@objc_msgSend}}
return [C allocWithZone:3];
}
// Make sure we use a message and not a call as the return type is
// not a pointer type.
// CHECK-LABEL: define {{.*}}void @test_cannot_message_return_float
float test_cannot_message_return_float(C *c) {
// MSGS: {{call.*@objc_msgSend}}
// CALLS: {{call.*@objc_msgSend}}
return [c retain];
}
@interface TestSelf
+ (instancetype)alloc;
+ (instancetype)allocWithZone:(void*)zone;
+ (id)classMeth;
- (id)instanceMeth;
@end
@implementation TestSelf
// CHECK-LABEL: define internal i8* @"\01+[TestSelf classMeth]"(
+ (id)classMeth {
// MSGS: {{call.*@objc_msgSend}}
// MSGS: {{call.*@objc_msgSend}}
// CALLS: {{call.*@objc_allocWithZone\(}}
// CALLS: {{call.*@objc_alloc\(}}
[self allocWithZone:nil];
return [self alloc];
}
// CHECK-LABEL: define internal i8* @"\01-[TestSelf instanceMeth]"(
- (id)instanceMeth {
// MSGS: {{call.*@objc_msgSend}}
// MSGS: {{call.*@objc_msgSend}}
// CALLS: {{call.*@objc_msgSend}}
// CALLS: {{call.*@objc_msgSend}}
[self allocWithZone:nil];
return [self alloc];
}
@end
@interface NSString : NSObject
+ (void)retain_self;
- (void)retain_super;
@end
@implementation NSString
// Make sure we can convert a message to a dynamic receiver to a call
// CHECK-LABEL: define {{.*}}void @retain_self
+ (void)retain_self {
// MSGS: {{call.*@objc_msgSend}}
// CALLS: {{call.*@objc_retain}}
[self retain];
}
// Make sure we never convert a message to super to a call
// CHECK-LABEL: define {{.*}}void @retain_super
- (void)retain_super {
// MSGS: {{call.*@objc_msgSend}}
// CALLS: {{call.*@objc_msgSend}}
[super retain];
}
@end
@class Ety;
// CHECK-LABEL: define {{.*}}void @testException_release
void testException_release(NSObject *a) {
// MSGS: {{invoke.*@objc_msgSend}}
// CALLS: invoke{{.*}}void @objc_release(i8* %
@try {
[a release];
} @catch (Ety *e) {
}
}
// CHECK-LABEL: define {{.*}}void @testException_autorelease
void testException_autorelease(NSObject *a) {
@try {
// MSGS: {{invoke.*@objc_msgSend}}
// CALLS: invoke{{.*}}objc_autorelease(i8* %
[a autorelease];
} @catch (Ety *e) {
}
}
// CHECK-LABEL: define {{.*}}void @testException_retain
void testException_retain(NSObject *a) {
@try {
// MSGS: {{invoke.*@objc_msgSend}}
// CALLS: invoke{{.*}}@objc_retain(i8* %
[a retain];
} @catch (Ety *e) {
}
}
// CHECK-LABEL: define {{.*}}void @testException_alloc(
void testException_alloc() {
@try {
// MSGS: {{invoke.*@objc_msgSend}}
// CALLS: invoke{{.*}}@objc_alloc(i8* %
[A alloc];
} @catch (Ety *e) {
}
}
// CHECK-LABEL: define {{.*}}void @testException_allocWithZone
void testException_allocWithZone() {
@try {
// MSGS: {{invoke.*@objc_msgSend}}
// CALLS: invoke{{.*}}@objc_allocWithZone(i8* %
[A allocWithZone:nil];
} @catch (Ety *e) {
}
}
|