John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -emit-llvm -triple i686-apple-darwin9 -fobjc-runtime=macosx-fragile-10.5 -o - %s -O2 | FileCheck %s |
Fariborz Jahanian | b79e661 | 2008-11-17 18:03:28 +0000 | [diff] [blame] | 2 | |
Fariborz Jahanian | f2878e5 | 2008-11-21 19:21:53 +0000 | [diff] [blame] | 3 | @interface MyClass |
| 4 | { |
| 5 | } |
| 6 | - (void)method; |
| 7 | @end |
| 8 | |
| 9 | @implementation MyClass |
| 10 | |
John McCall | 87bb582 | 2010-07-31 23:20:56 +0000 | [diff] [blame] | 11 | // CHECK: define internal void @"\01-[MyClass method]" |
Fariborz Jahanian | f2878e5 | 2008-11-21 19:21:53 +0000 | [diff] [blame] | 12 | - (void)method |
| 13 | { |
Aaron Ballman | 2d234d73 | 2012-09-06 16:44:16 +0000 | [diff] [blame] | 14 | // CHECK: call i32 @objc_sync_enter |
John McCall | 87bb582 | 2010-07-31 23:20:56 +0000 | [diff] [blame] | 15 | // CHECK: call void @objc_exception_try_enter |
| 16 | // CHECK: call i32 @_setjmp |
| 17 | @synchronized(self) { |
| 18 | } |
Fariborz Jahanian | f2878e5 | 2008-11-21 19:21:53 +0000 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | @end |
| 22 | |
John McCall | 87bb582 | 2010-07-31 23:20:56 +0000 | [diff] [blame] | 23 | // CHECK: define void @foo( |
Fariborz Jahanian | b79e661 | 2008-11-17 18:03:28 +0000 | [diff] [blame] | 24 | void foo(id a) { |
John McCall | 87bb582 | 2010-07-31 23:20:56 +0000 | [diff] [blame] | 25 | // CHECK: [[A:%.*]] = alloca i8* |
John McCall | 0b25172 | 2010-08-04 05:59:32 +0000 | [diff] [blame] | 26 | // CHECK: [[SYNC:%.*]] = alloca i8* |
John McCall | 87bb582 | 2010-07-31 23:20:56 +0000 | [diff] [blame] | 27 | |
John McCall | 0b25172 | 2010-08-04 05:59:32 +0000 | [diff] [blame] | 28 | // CHECK: store i8* [[AVAL:%.*]], i8** [[A]] |
Aaron Ballman | 2d234d73 | 2012-09-06 16:44:16 +0000 | [diff] [blame] | 29 | // CHECK-NEXT: call i32 @objc_sync_enter(i8* [[AVAL]]) |
John McCall | 0b25172 | 2010-08-04 05:59:32 +0000 | [diff] [blame] | 30 | // CHECK-NEXT: store i8* [[AVAL]], i8** [[SYNC]] |
| 31 | // CHECK-NEXT: call void @objc_exception_try_enter |
| 32 | // CHECK: call i32 @_setjmp |
Fariborz Jahanian | b79e661 | 2008-11-17 18:03:28 +0000 | [diff] [blame] | 33 | @synchronized(a) { |
John McCall | 0b25172 | 2010-08-04 05:59:32 +0000 | [diff] [blame] | 34 | // This is unreachable, but the optimizers can't know that. |
| 35 | // CHECK: call void asm sideeffect "", "=*m,=*m,=*m"(i8** [[A]], i8** [[SYNC]] |
Aaron Ballman | 2d234d73 | 2012-09-06 16:44:16 +0000 | [diff] [blame] | 36 | // CHECK: call i32 @objc_sync_exit |
John McCall | 0b25172 | 2010-08-04 05:59:32 +0000 | [diff] [blame] | 37 | // CHECK: call i8* @objc_exception_extract |
| 38 | // CHECK: call void @objc_exception_throw |
| 39 | // CHECK: unreachable |
| 40 | |
| 41 | // CHECK: call void @objc_exception_try_exit |
| 42 | // CHECK: [[T:%.*]] = load i8** [[SYNC]] |
Aaron Ballman | 2d234d73 | 2012-09-06 16:44:16 +0000 | [diff] [blame] | 43 | // CHECK-NEXT: call i32 @objc_sync_exit |
John McCall | 87bb582 | 2010-07-31 23:20:56 +0000 | [diff] [blame] | 44 | // CHECK: ret void |
Fariborz Jahanian | b79e661 | 2008-11-17 18:03:28 +0000 | [diff] [blame] | 45 | return; |
| 46 | } |
John McCall | 87bb582 | 2010-07-31 23:20:56 +0000 | [diff] [blame] | 47 | |
Fariborz Jahanian | b79e661 | 2008-11-17 18:03:28 +0000 | [diff] [blame] | 48 | } |
| 49 | |
John McCall | 87bb582 | 2010-07-31 23:20:56 +0000 | [diff] [blame] | 50 | // CHECK: define i32 @f0( |
Daniel Dunbar | 1c56667 | 2009-02-24 01:43:46 +0000 | [diff] [blame] | 51 | int f0(id a) { |
John McCall | 87bb582 | 2010-07-31 23:20:56 +0000 | [diff] [blame] | 52 | // TODO: we can optimize the ret to a constant if we can figure out |
| 53 | // either that x isn't stored to within the synchronized block or |
| 54 | // that the synchronized block can't longjmp. |
| 55 | |
| 56 | // CHECK: [[X:%.*]] = alloca i32 |
| 57 | // CHECK: store i32 1, i32* [[X]] |
Daniel Dunbar | 1c56667 | 2009-02-24 01:43:46 +0000 | [diff] [blame] | 58 | int x = 0; |
| 59 | @synchronized((x++, a)) { |
| 60 | } |
John McCall | 87bb582 | 2010-07-31 23:20:56 +0000 | [diff] [blame] | 61 | |
| 62 | // CHECK: [[T:%.*]] = load i32* [[X]] |
| 63 | // CHECK: ret i32 [[T]] |
| 64 | return x; |
Daniel Dunbar | 1c56667 | 2009-02-24 01:43:46 +0000 | [diff] [blame] | 65 | } |
Fariborz Jahanian | f2878e5 | 2008-11-21 19:21:53 +0000 | [diff] [blame] | 66 | |
John McCall | 87bb582 | 2010-07-31 23:20:56 +0000 | [diff] [blame] | 67 | // CHECK: define void @f1( |
Daniel Dunbar | 1c56667 | 2009-02-24 01:43:46 +0000 | [diff] [blame] | 68 | void f1(id a) { |
John McCall | 87bb582 | 2010-07-31 23:20:56 +0000 | [diff] [blame] | 69 | // Check that the return doesn't go through the cleanup. |
| 70 | extern void opaque(void); |
| 71 | opaque(); |
| 72 | |
| 73 | // CHECK: call void @opaque() |
| 74 | // CHECK-NEXT: ret void |
| 75 | |
Daniel Dunbar | 1c56667 | 2009-02-24 01:43:46 +0000 | [diff] [blame] | 76 | @synchronized(({ return; }), a) { |
| 77 | return; |
| 78 | } |
| 79 | } |