blob: b71337972dced900ebcdb8c58ad99c60ce3d3747 [file] [log] [blame]
John McCall87bb5822010-07-31 23:20:56 +00001// RUN: %clang_cc1 -emit-llvm -triple=i686-apple-darwin9 -o - %s -O2 | FileCheck %s
Fariborz Jahanianb79e6612008-11-17 18:03:28 +00002
Fariborz Jahanianf2878e52008-11-21 19:21:53 +00003@interface MyClass
4{
5}
6- (void)method;
7@end
8
9@implementation MyClass
10
John McCall87bb5822010-07-31 23:20:56 +000011// CHECK: define internal void @"\01-[MyClass method]"
Fariborz Jahanianf2878e52008-11-21 19:21:53 +000012- (void)method
13{
John McCall87bb5822010-07-31 23:20:56 +000014 // CHECK: call void @objc_sync_enter
15 // CHECK: call void @objc_exception_try_enter
16 // CHECK: call i32 @_setjmp
17 @synchronized(self) {
18 }
Fariborz Jahanianf2878e52008-11-21 19:21:53 +000019}
20
21@end
22
John McCall87bb5822010-07-31 23:20:56 +000023// CHECK: define void @foo(
Fariborz Jahanianb79e6612008-11-17 18:03:28 +000024void foo(id a) {
John McCall87bb5822010-07-31 23:20:56 +000025 // CHECK: [[A:%.*]] = alloca i8*
26
27 // CHECK: call void @objc_sync_enter
28 // CHECK: call void @objc_exception_try_enter
29 // CHECK: call i32 @_setjmp
Fariborz Jahanianb79e6612008-11-17 18:03:28 +000030 @synchronized(a) {
John McCall87bb5822010-07-31 23:20:56 +000031 // CHECK: call void @objc_exception_try_exit
32 // CHECK: call void @objc_sync_exit
33 // CHECK: ret void
Fariborz Jahanianb79e6612008-11-17 18:03:28 +000034 return;
35 }
John McCall87bb5822010-07-31 23:20:56 +000036
37 // This is unreachable, but the optimizers can't know that.
38 // CHECK: call void asm sideeffect "", "=*m"(i8** [[A]])
39 // CHECK: call i8* @objc_exception_extract
40 // CHECK: call void @objc_sync_exit
41 // CHECK: call void @objc_exception_throw
42 // CHECK: unreachable
Fariborz Jahanianb79e6612008-11-17 18:03:28 +000043}
44
John McCall87bb5822010-07-31 23:20:56 +000045// CHECK: define i32 @f0(
Daniel Dunbar1c566672009-02-24 01:43:46 +000046int f0(id a) {
John McCall87bb5822010-07-31 23:20:56 +000047 // TODO: we can optimize the ret to a constant if we can figure out
48 // either that x isn't stored to within the synchronized block or
49 // that the synchronized block can't longjmp.
50
51 // CHECK: [[X:%.*]] = alloca i32
52 // CHECK: store i32 1, i32* [[X]]
Daniel Dunbar1c566672009-02-24 01:43:46 +000053 int x = 0;
54 @synchronized((x++, a)) {
55 }
John McCall87bb5822010-07-31 23:20:56 +000056
57 // CHECK: [[T:%.*]] = load i32* [[X]]
58 // CHECK: ret i32 [[T]]
59 return x;
Daniel Dunbar1c566672009-02-24 01:43:46 +000060}
Fariborz Jahanianf2878e52008-11-21 19:21:53 +000061
John McCall87bb5822010-07-31 23:20:56 +000062// CHECK: define void @f1(
Daniel Dunbar1c566672009-02-24 01:43:46 +000063void f1(id a) {
John McCall87bb5822010-07-31 23:20:56 +000064 // Check that the return doesn't go through the cleanup.
65 extern void opaque(void);
66 opaque();
67
68 // CHECK: call void @opaque()
69 // CHECK-NEXT: ret void
70
Daniel Dunbar1c566672009-02-24 01:43:46 +000071 @synchronized(({ return; }), a) {
72 return;
73 }
74}