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