]> granicus.if.org Git - clang/commitdiff
Fixed bugzilla bug# 3095 related to code gen. for @synchronized.
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 21 Nov 2008 19:21:53 +0000 (19:21 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 21 Nov 2008 19:21:53 +0000 (19:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59838 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGObjCMac.cpp
test/CodeGenObjC/synchronized.m

index ff2d93a3317ff4e605e076a748c262f984b8f2d4..8eb81a4b4b60bfb3e4e3d00270612b5953c10b2d 100644 (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);
  
index 0222846ccd710b58544169bdaff3a784a028ee53..c74a83edbe35dec542384ad248a4302efdaba3f2 100644 (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) {
   }
 }
 
+
+