Debian Codegraph @

clang/test/CodeGenObjC/objc-alloc-init.m

raw
1 // RUN: %clang_cc1 %s -fobjc-exceptions -fexceptions -fobjc-runtime=macosx-10.14.4 -emit-llvm -O0 -o - | FileCheck %s --check-prefix=OPTIMIZED --check-prefix=EITHER
2 // RUN: %clang_cc1 %s -fobjc-exceptions -fexceptions -fobjc-runtime=macosx-10.14.3 -emit-llvm -O0 -o - | FileCheck %s --check-prefix=NOT_OPTIMIZED --check-prefix=EITHER
3 // RUN: %clang_cc1 %s -fobjc-exceptions -fexceptions -fobjc-runtime=ios-12.2 -emit-llvm -O0 -o - | FileCheck %s --check-prefix=OPTIMIZED --check-prefix=EITHER
4 // RUN: %clang_cc1 %s -fobjc-exceptions -fexceptions -fobjc-runtime=ios-12.1 -emit-llvm -O0 -o - | FileCheck %s --check-prefix=NOT_OPTIMIZED --check-prefix=EITHER
5
6 @interface X
7 +(X *)alloc;
8 -(X *)init;
9 @end
10
11 void f(void) {
12 [[X alloc] init];
13 // OPTIMIZED: call ptr @objc_alloc_init(
14 // NOT_OPTIMIZED: call ptr @objc_alloc(
15
16 @try {
17 [[X alloc] init];
18 } @catch (X *x) {
19 }
20 // OPTIMIZED: invoke ptr @objc_alloc_init(
21 // NOT_OPTIMIZED: invoke ptr @objc_alloc(
22 }
23
24 @interface Y : X
25 +(Class)class;
26 +(void)meth;
27 -(void)instanceMeth;
28 @end
29
30 @implementation Y
31 +(Class)class {
32 return self;
33 }
34 +(void)meth {
35 [[self alloc] init];
36 // OPTIMIZED: call ptr @objc_alloc_init(
37 // NOT_OPTIMIZED: call ptr @objc_alloc(
38 }
39 + (void)meth2 {
40 [[[self class] alloc] init];
41 // OPTIMIZED: call ptr @objc_alloc_init(
42 // NOT_OPTIMIZED: call ptr @objc_alloc(
43 }
44 -(void)instanceMeth {
45 // EITHER-NOT: call ptr @objc_alloc
46 // EITHER: call {{.*}} @objc_msgSend
47 // EITHER: call {{.*}} @objc_msgSend
48 [[(id)self alloc] init];
49 }
50 @end
51
52 @interface Base
53 -(instancetype)init;
54 @end
55
56 @interface Derived : Base
57 @end
58 @implementation Derived
59 -(void)meth {
60 [super init];
61 }
62 @end