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