xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenObjCXX/exceptions-legacy.mm (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -triple i386-apple-darwin10 -fobjc-runtime=macosx-fragile-10.5 -emit-llvm -fexceptions -fobjc-exceptions -O2 -o - %s | FileCheck %s
2*f4a2713aSLionel Sambuc
3*f4a2713aSLionel Sambuc// Test we maintain at least a basic amount of interoperation between
4*f4a2713aSLionel Sambuc// ObjC and C++ exceptions in the legacy runtime.
5*f4a2713aSLionel Sambuc
6*f4a2713aSLionel Sambuc// rdar://12364847
7*f4a2713aSLionel Sambuc
8*f4a2713aSLionel Sambucvoid foo(void);
9*f4a2713aSLionel Sambuc
10*f4a2713aSLionel Sambucvoid test0(id obj) {
11*f4a2713aSLionel Sambuc  @synchronized(obj) {
12*f4a2713aSLionel Sambuc    foo();
13*f4a2713aSLionel Sambuc  }
14*f4a2713aSLionel Sambuc}
15*f4a2713aSLionel Sambuc// CHECK-LABEL:    define void @_Z5test0P11objc_object(
16*f4a2713aSLionel Sambuc//   Enter the @synchronized block.
17*f4a2713aSLionel Sambuc// CHECK:      call i32 @objc_sync_enter(i8* [[OBJ:%.*]])
18*f4a2713aSLionel Sambuc// CHECK:      call void @objc_exception_try_enter([[BUF_T:%.*]]* [[BUF:%.*]])
19*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = getelementptr [[BUF_T]]* [[BUF]], i32 0, i32 0, i32 0
20*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = call i32 @_setjmp(i32* [[T0]])
21*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = icmp eq i32 [[T1]], 0
22*f4a2713aSLionel Sambuc// CHECK-NEXT: br i1 [[T2]],
23*f4a2713aSLionel Sambuc
24*f4a2713aSLionel Sambuc//   Body.
25*f4a2713aSLionel Sambuc// CHECK:      invoke void @_Z3foov()
26*f4a2713aSLionel Sambuc
27*f4a2713aSLionel Sambuc//   Leave the @synchronized.  The reload of obj here is unnecessary.
28*f4a2713aSLionel Sambuc// CHECK:      call void @objc_exception_try_exit([[BUF_T]]* [[BUF]])
29*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = load i8**
30*f4a2713aSLionel Sambuc// CHECK-NEXT: call i32 @objc_sync_exit(i8* [[T0]])
31*f4a2713aSLionel Sambuc// CHECK-NEXT: ret void
32*f4a2713aSLionel Sambuc
33*f4a2713aSLionel Sambuc//   Real EH cleanup.
34*f4a2713aSLionel Sambuc// CHECK:      [[T0:%.*]] = landingpad
35*f4a2713aSLionel Sambuc// CHECK-NEXT:    cleanup
36*f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_exception_try_exit([[BUF_T]]* [[BUF]])
37*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = load i8**
38*f4a2713aSLionel Sambuc// CHECK-NEXT: call i32 @objc_sync_exit(i8* [[T0]])
39*f4a2713aSLionel Sambuc// CHECK-NEXT: resume
40*f4a2713aSLionel Sambuc
41*f4a2713aSLionel Sambuc//   ObjC EH "cleanup".
42*f4a2713aSLionel Sambuc// CHECK:      [[T0:%.*]] = load i8**
43*f4a2713aSLionel Sambuc// CHECK-NEXT: call i32 @objc_sync_exit(i8* [[T0]])
44*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = call i8* @objc_exception_extract([[BUF_T]]* [[BUF]])
45*f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_exception_throw(i8* [[T0]])
46*f4a2713aSLionel Sambuc// CHECK-NEXT: unreachable
47*f4a2713aSLionel Sambuc
48*f4a2713aSLionel Sambucvoid test1(id obj, bool *failed) {
49*f4a2713aSLionel Sambuc  @try {
50*f4a2713aSLionel Sambuc    foo();
51*f4a2713aSLionel Sambuc  } @catch (...) {
52*f4a2713aSLionel Sambuc    *failed = true;
53*f4a2713aSLionel Sambuc  }
54*f4a2713aSLionel Sambuc}
55*f4a2713aSLionel Sambuc// CHECK-LABEL:    define void @_Z5test1P11objc_objectPb(
56*f4a2713aSLionel Sambuc//   Enter the @try block.
57*f4a2713aSLionel Sambuc// CHECK:      call void @objc_exception_try_enter([[BUF_T]]* [[BUF:%.*]])
58*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T0:%.*]] = getelementptr [[BUF_T]]* [[BUF]], i32 0, i32 0, i32 0
59*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T1:%.*]] = call i32 @_setjmp(i32* [[T0]])
60*f4a2713aSLionel Sambuc// CHECK-NEXT: [[T2:%.*]] = icmp eq i32 [[T1]], 0
61*f4a2713aSLionel Sambuc// CHECK-NEXT: br i1 [[T2]],
62*f4a2713aSLionel Sambuc
63*f4a2713aSLionel Sambuc//   Body.
64*f4a2713aSLionel Sambuc// CHECK:      invoke void @_Z3foov()
65*f4a2713aSLionel Sambuc
66*f4a2713aSLionel Sambuc//   Leave the @try.
67*f4a2713aSLionel Sambuc// CHECK:      call void @objc_exception_try_exit([[BUF_T]]* [[BUF]])
68*f4a2713aSLionel Sambuc// CHECK-NEXT: br label
69*f4a2713aSLionel Sambuc// CHECK:      ret void
70*f4a2713aSLionel Sambuc
71*f4a2713aSLionel Sambuc//   Real EH cleanup.
72*f4a2713aSLionel Sambuc// CHECK:      [[T0:%.*]] = landingpad
73*f4a2713aSLionel Sambuc// CHECK-NEXT:    cleanup
74*f4a2713aSLionel Sambuc// CHECK-NEXT: call void @objc_exception_try_exit([[BUF_T]]* [[BUF]])
75*f4a2713aSLionel Sambuc// CHECK-NEXT: resume
76*f4a2713aSLionel Sambuc
77*f4a2713aSLionel Sambuc//   Catch handler.  Reload of 'failed' address is unnecessary.
78*f4a2713aSLionel Sambuc// CHECK:      [[T0:%.*]] = load i8**
79*f4a2713aSLionel Sambuc// CHECK-NEXT: store i8 1, i8* [[T0]],
80*f4a2713aSLionel Sambuc// CHECK-NEXT: br label
81