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+(void)meth;
26-(void)instanceMeth;
27@end
28
29@implementation Y
30+(void)meth {
31  [[self alloc] init];
32  // OPTIMIZED: call i8* @objc_alloc_init(
33  // NOT_OPTIMIZED: call i8* @objc_alloc(
34}
35-(void)instanceMeth {
36  // EITHER-NOT: call i8* @objc_alloc
37  // EITHER: call {{.*}} @objc_msgSend
38  // EITHER: call {{.*}} @objc_msgSend
39  [[self alloc] init];
40}
41@end
42
43// rdar://48247290
44@interface Base
45-(instancetype)init;
46@end
47
48@interface Derived : Base
49@end
50@implementation Derived
51-(void)meth {
52  [super init];
53}
54@end
55