xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenObjC/arc-exceptions.m (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-arc -fexceptions -fobjc-exceptions -fobjc-runtime-has-weak -o - %s | FileCheck %s
2*f4a2713aSLionel Sambuc
3*f4a2713aSLionel Sambuc@class Ety;
4*f4a2713aSLionel Sambuc
5*f4a2713aSLionel Sambuc// These first two tests are all PR11732 / rdar://problem/10667070.
6*f4a2713aSLionel Sambuc
7*f4a2713aSLionel Sambucvoid test0_helper(void);
8*f4a2713aSLionel Sambucvoid test0(void) {
9*f4a2713aSLionel Sambuc  @try {
10*f4a2713aSLionel Sambuc    test0_helper();
11*f4a2713aSLionel Sambuc  } @catch (Ety *e) {
12*f4a2713aSLionel Sambuc  }
13*f4a2713aSLionel Sambuc}
14*f4a2713aSLionel Sambuc// CHECK-LABEL: define void @test0()
15*f4a2713aSLionel Sambuc// CHECK:      [[E:%.*]] = alloca [[ETY:%.*]]*, align 8
16*f4a2713aSLionel Sambuc// CHECK-NEXT: invoke void @test0_helper()
17*f4a2713aSLionel Sambuc// CHECK:      [[T0:%.*]] = call i8* @objc_begin_catch(
18*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to [[ETY]]*
19*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = bitcast [[ETY]]* [[T1]] to i8*
20*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T3:%.*]] = call i8* @objc_retain(i8* [[T2]]) [[NUW:#[0-9]+]]
21*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T4:%.*]] = bitcast i8* [[T3]] to [[ETY]]*
22*f4a2713aSLionel Sambuc// CHECK-NEXT: store [[ETY]]* [[T4]], [[ETY]]** [[E]]
23*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = bitcast [[ETY]]** [[E]] to i8**
24*f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_storeStrong(i8** [[T0]], i8* null) [[NUW]]
25*f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_end_catch() [[NUW]]
26*f4a2713aSLionel Sambuc
27*f4a2713aSLionel Sambucvoid test1_helper(void);
28*f4a2713aSLionel Sambucvoid test1(void) {
29*f4a2713aSLionel Sambuc  @try {
30*f4a2713aSLionel Sambuc    test1_helper();
31*f4a2713aSLionel Sambuc  } @catch (__weak Ety *e) {
32*f4a2713aSLionel Sambuc  }
33*f4a2713aSLionel Sambuc}
34*f4a2713aSLionel Sambuc// CHECK-LABEL: define void @test1()
35*f4a2713aSLionel Sambuc// CHECK:      [[E:%.*]] = alloca [[ETY:%.*]]*, align 8
36*f4a2713aSLionel Sambuc// CHECK-NEXT: invoke void @test1_helper()
37*f4a2713aSLionel Sambuc// CHECK:      [[T0:%.*]] = call i8* @objc_begin_catch(
38*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to [[ETY]]*
39*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = bitcast [[ETY]]** [[E]] to i8**
40*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T3:%.*]] = bitcast [[ETY]]* [[T1]] to i8*
41*f4a2713aSLionel Sambuc// CHECK-NEXT: call i8* @objc_initWeak(i8** [[T2]], i8* [[T3]]) [[NUW]]
42*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = bitcast [[ETY]]** [[E]] to i8**
43*f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_destroyWeak(i8** [[T0]]) [[NUW]]
44*f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_end_catch() [[NUW]]
45*f4a2713aSLionel Sambuc
46*f4a2713aSLionel Sambuc// CHECK: attributes [[NUW]] = { nounwind }
47