blob: fb5300d15e4c59611cd941863b2e5436f50b6b9a [file] [log] [blame]
John McCall97017312012-01-17 20:16:56 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-arc -fexceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime-has-weak -o - %s | FileCheck %s
2
3@class Ety;
4
5// These first four tests are all PR11732 / rdar://problem/10667070.
6
7void test0_helper(void);
8void test0(void) {
9 @try {
10 test0_helper();
11 } @catch (Ety *e) {
12 }
13}
14// CHECK: define void @_Z5test0v()
15// CHECK: [[E:%.*]] = alloca [[ETY:%.*]]*, align 8
16// CHECK-NEXT: invoke void @_Z12test0_helperv()
17// CHECK: [[T0:%.*]] = call i8* @objc_begin_catch(
18// CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to [[ETY]]*
19// CHECK-NEXT: [[T2:%.*]] = bitcast [[ETY]]* [[T1]] to i8*
20// CHECK-NEXT: [[T3:%.*]] = call i8* @objc_retain(i8* [[T2]]) nounwind
21// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to [[ETY]]*
22// CHECK-NEXT: store [[ETY]]* [[T4]], [[ETY]]** [[E]]
John McCalle68b8f42012-10-17 02:28:37 +000023// CHECK-NEXT: [[T0:%.*]] = bitcast [[ETY]]** [[E]] to i8**
24// CHECK-NEXT: call void @objc_storeStrong(i8** [[T0]], i8* null) nounwind
John McCall97017312012-01-17 20:16:56 +000025// CHECK-NEXT: call void @objc_end_catch() nounwind
26
27void test1_helper(void);
28void test1(void) {
29 @try {
30 test1_helper();
31 } @catch (__weak Ety *e) {
32 }
33}
34// CHECK: define void @_Z5test1v()
35// CHECK: [[E:%.*]] = alloca [[ETY:%.*]]*, align 8
36// CHECK-NEXT: invoke void @_Z12test1_helperv()
37// CHECK: [[T0:%.*]] = call i8* @objc_begin_catch(
38// CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to [[ETY]]*
39// CHECK-NEXT: [[T2:%.*]] = bitcast [[ETY]]** [[E]] to i8**
40// CHECK-NEXT: [[T3:%.*]] = bitcast [[ETY]]* [[T1]] to i8*
41// CHECK-NEXT: call i8* @objc_initWeak(i8** [[T2]], i8* [[T3]]) nounwind
42// CHECK-NEXT: [[T0:%.*]] = bitcast [[ETY]]** [[E]] to i8**
43// CHECK-NEXT: call void @objc_destroyWeak(i8** [[T0]]) nounwind
44// CHECK-NEXT: call void @objc_end_catch() nounwind
45
46void test2_helper(void);
47void test2(void) {
48 try {
49 test2_helper();
50 } catch (Ety *e) {
51 }
52}
53// CHECK: define void @_Z5test2v()
54// CHECK: [[E:%.*]] = alloca [[ETY:%.*]]*, align 8
55// CHECK-NEXT: invoke void @_Z12test2_helperv()
56// CHECK: [[T0:%.*]] = call i8* @__cxa_begin_catch(
57// CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to [[ETY]]*
58// CHECK-NEXT: [[T2:%.*]] = bitcast [[ETY]]* [[T1]] to i8*
59// CHECK-NEXT: [[T3:%.*]] = call i8* @objc_retain(i8* [[T2]]) nounwind
60// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to [[ETY]]*
61// CHECK-NEXT: store [[ETY]]* [[T4]], [[ETY]]** [[E]]
John McCalle68b8f42012-10-17 02:28:37 +000062// CHECK-NEXT: [[T0:%.*]] = bitcast [[ETY]]** [[E]] to i8**
63// CHECK-NEXT: call void @objc_storeStrong(i8** [[T0]], i8* null) nounwind
John McCall97017312012-01-17 20:16:56 +000064// CHECK-NEXT: call void @__cxa_end_catch() nounwind
65
66void test3_helper(void);
67void test3(void) {
68 try {
69 test3_helper();
70 } catch (Ety * __weak e) {
71 }
72}
73// CHECK: define void @_Z5test3v()
74// CHECK: [[E:%.*]] = alloca [[ETY:%.*]]*, align 8
75// CHECK-NEXT: invoke void @_Z12test3_helperv()
76// CHECK: [[T0:%.*]] = call i8* @__cxa_begin_catch(
77// CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to [[ETY]]*
78// CHECK-NEXT: [[T2:%.*]] = bitcast [[ETY]]** [[E]] to i8**
79// CHECK-NEXT: [[T3:%.*]] = bitcast [[ETY]]* [[T1]] to i8*
80// CHECK-NEXT: call i8* @objc_initWeak(i8** [[T2]], i8* [[T3]]) nounwind
81// CHECK-NEXT: [[T0:%.*]] = bitcast [[ETY]]** [[E]] to i8**
82// CHECK-NEXT: call void @objc_destroyWeak(i8** [[T0]]) nounwind
83// CHECK-NEXT: call void @__cxa_end_catch() nounwind