Fixed bugzilla bug# 3095 related to code gen. for @synchronized.

llvm-svn: 59838
This commit is contained in:
Fariborz Jahanian 2008-11-21 19:21:53 +00:00
parent 57d0b88830
commit e2caaaa13c
2 changed files with 31 additions and 7 deletions

View File

@ -1589,9 +1589,10 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
"_rethrow");
if (!isTry) {
// For @synchronized, call objc_sync_enter(sync.expr)
CGF.Builder.CreateCall(ObjCTypes.SyncEnterFn,
CGF.EmitScalarExpr(
cast<ObjCAtSynchronizedStmt>(S).getSynchExpr()));
llvm::Value *Arg = CGF.EmitScalarExpr(
cast<ObjCAtSynchronizedStmt>(S).getSynchExpr());
Arg = CGF.Builder.CreateBitCast(Arg, ObjCTypes.ObjectPtrTy);
CGF.Builder.CreateCall(ObjCTypes.SyncEnterFn, Arg);
}
// Enter a new try block and call setjmp.
@ -1748,11 +1749,14 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
cast<ObjCAtTryStmt>(S).getFinallyStmt())
CGF.EmitStmt(FinallyStmt->getFinallyBody());
}
else
else {
// For @synchronized objc_sync_exit(expr); As finally's sole statement.
CGF.Builder.CreateCall(ObjCTypes.SyncExitFn,
CGF.EmitScalarExpr(
cast<ObjCAtSynchronizedStmt>(S).getSynchExpr()));
// For @synchronized, call objc_sync_enter(sync.expr)
llvm::Value *Arg = CGF.EmitScalarExpr(
cast<ObjCAtSynchronizedStmt>(S).getSynchExpr());
Arg = CGF.Builder.CreateBitCast(Arg, ObjCTypes.ObjectPtrTy);
CGF.Builder.CreateCall(ObjCTypes.SyncExitFn, Arg);
}
CGF.EmitBlock(FinallyJump);

View File

@ -3,6 +3,24 @@
#include <stdio.h>
@interface MyClass
{
}
- (void)method;
@end
@implementation MyClass
- (void)method
{
@synchronized(self)
{
NSLog(@"sync");
}
}
@end
void foo(id a) {
@synchronized(a) {
printf("Swimming? No.");
@ -10,3 +28,5 @@ void foo(id a) {
}
}