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
11void f() {
12  [[X alloc] init];
13  // OPTIMIZED: call i8* @objc_alloc_init(
14  // NOT_OPTIMIZED: call i8* @objc_alloc(
15
16  @try {
17    [[X alloc] init];
18  } @catch (X *x) {
19  }
20  // OPTIMIZED: invoke i8* @objc_alloc_init(
21  // NOT_OPTIMIZED: invoke i8* @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 i8* @objc_alloc_init(
37  // NOT_OPTIMIZED: call i8* @objc_alloc(
38}
39+ (void)meth2 {
40  [[[self class] alloc] init];
41  // OPTIMIZED: call i8* @objc_alloc_init(
42  // NOT_OPTIMIZED: call i8* @objc_alloc(
43}
44-(void)instanceMeth {
45  // EITHER-NOT: call i8* @objc_alloc
46  // EITHER: call {{.*}} @objc_msgSend
47  // EITHER: call {{.*}} @objc_msgSend
48  [[(id)self alloc] init];
49}
50@end
51
52// rdar://48247290
53@interface Base
54-(instancetype)init;
55@end
56
57@interface Derived : Base
58@end
59@implementation Derived
60-(void)meth {
61  [super init];
62}
63@end
64