]> granicus.if.org Git - clang/commitdiff
Convert the ObjC @synchronized cleanups to laziness. This is not actually
authorJohn McCall <rjmccall@apple.com>
Wed, 21 Jul 2010 00:41:47 +0000 (00:41 +0000)
committerJohn McCall <rjmccall@apple.com>
Wed, 21 Jul 2010 00:41:47 +0000 (00:41 +0000)
a big deal, except that I want to eliminate the shared-code EH cleanups
in preparation for a significant algorithmic fix.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108973 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGObjCGNU.cpp
lib/CodeGen/CGObjCMac.cpp

index 1b8705055eabbb230be9f7ddd93273ca0b90fc6f..567b8c3d7de0f38d4d83c6de7523bcaa2f6b14fc 100644 (file)
@@ -1855,6 +1855,19 @@ llvm::Constant *CGObjCGNU::EnumerationMutationFunction() {
   return CGM.CreateRuntimeFunction(FTy, "objc_enumerationMutation");
 }
 
+namespace {
+  struct CallSyncExit : EHScopeStack::LazyCleanup {
+    llvm::Value *SyncExitFn;
+    llvm::Value *SyncArg;
+    CallSyncExit(llvm::Value *SyncExitFn, llvm::Value *SyncArg)
+      : SyncExitFn(SyncExitFn), SyncArg(SyncArg) {}
+
+    void Emit(CodeGenFunction &CGF, bool IsForEHCleanup) {
+      CGF.Builder.CreateCall(SyncExitFn, SyncArg)->setDoesNotThrow();
+    }
+  };
+}
+
 void CGObjCGNU::EmitSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
                                      const ObjCAtSynchronizedStmt &S) {
   std::vector<const llvm::Type*> Args(1, IdTy);
@@ -1871,13 +1884,9 @@ void CGObjCGNU::EmitSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
   CGF.Builder.CreateCall(SyncEnter, SyncArg);
 
   // Register an all-paths cleanup to release the lock.
-  {
-    CodeGenFunction::CleanupBlock ReleaseScope(CGF, NormalAndEHCleanup);
-
-    llvm::Value *SyncExit = CGM.CreateRuntimeFunction(FTy, "objc_sync_exit");
-    SyncArg = CGF.Builder.CreateBitCast(SyncArg, IdTy);
-    CGF.Builder.CreateCall(SyncExit, SyncArg);
-  }
+  llvm::Value *SyncExit = CGM.CreateRuntimeFunction(FTy, "objc_sync_exit");
+  CGF.EHStack.pushLazyCleanup<CallSyncExit>(NormalAndEHCleanup,
+                                            SyncExit, SyncArg);
 
   // Emit the body of the statement.
   CGF.EmitStmt(S.getSynchBody());
index 03764d27ff157d9cc06ff7534b88d681df2d299c..4e5c34b174c0b1d79b05277e8f346b943081cd06 100644 (file)
@@ -5695,6 +5695,19 @@ void CGObjCNonFragileABIMac::EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF,
   return;
 }
 
+namespace {
+  struct CallSyncExit : EHScopeStack::LazyCleanup {
+    llvm::Value *SyncExitFn;
+    llvm::Value *SyncArg;
+    CallSyncExit(llvm::Value *SyncExitFn, llvm::Value *SyncArg)
+      : SyncExitFn(SyncExitFn), SyncArg(SyncArg) {}
+
+    void Emit(CodeGenFunction &CGF, bool IsForEHCleanup) {
+      CGF.Builder.CreateCall(SyncExitFn, SyncArg)->setDoesNotThrow();
+    }
+  };
+}
+
 void
 CGObjCNonFragileABIMac::EmitSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
                                              const ObjCAtSynchronizedStmt &S) {
@@ -5707,12 +5720,9 @@ CGObjCNonFragileABIMac::EmitSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
     ->setDoesNotThrow();
 
   // Register an all-paths cleanup to release the lock.
-  {
-    CodeGenFunction::CleanupBlock ReleaseScope(CGF, NormalAndEHCleanup);
-
-    CGF.Builder.CreateCall(ObjCTypes.getSyncExitFn(), SyncArg)
-      ->setDoesNotThrow();
-  }
+  CGF.EHStack.pushLazyCleanup<CallSyncExit>(NormalAndEHCleanup,
+                                            ObjCTypes.getSyncExitFn(),
+                                            SyncArg);
 
   // Emit the body of the statement.
   CGF.EmitStmt(S.getSynchBody());