[cfe-commits] r125627 - in /cfe/trunk: lib/CodeGen/CGBlocks.cpp lib/CodeGen/CGBlocks.h test/CodeGenObjC/objc2-weak-block-call.m

John McCall rjmccall at apple.com
Tue Feb 15 16:49:34 PST 2011


Author: rjmccall
Date: Tue Feb 15 18:49:34 2011
New Revision: 125627

URL: http://llvm.org/viewvc/llvm-project?rev=125627&view=rev
Log:
Don't call objc_read_weak as part of emitting a block literal.
Nobody ever gave me a clear reason for why we were doing this, and
now it's apparently causing serious problems, so if *not* having this
causes problems, we get to solve them the right way this time.


Modified:
    cfe/trunk/lib/CodeGen/CGBlocks.cpp
    cfe/trunk/lib/CodeGen/CGBlocks.h
    cfe/trunk/test/CodeGenObjC/objc2-weak-block-call.m

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=125627&r1=125626&r2=125627&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Tue Feb 15 18:49:34 2011
@@ -27,8 +27,7 @@
 
 CGBlockInfo::CGBlockInfo(const BlockExpr *blockExpr, const char *N)
   : Name(N), CXXThisIndex(0), CanBeGlobal(false), NeedsCopyDispose(false),
-    HasCXXObject(false), HasWeakBlockVariable(false),
-    StructureType(0), Block(blockExpr) {
+    HasCXXObject(false), StructureType(0), Block(blockExpr) {
     
   // Skip asm prefix, if any.
   if (Name && Name[0] == '\01')
@@ -355,10 +354,6 @@
       // We have to copy/dispose of the __block reference.
       info.NeedsCopyDispose = true;
 
-      // Also note that it's weak for GC purposes.
-      if (variable->getType().isObjCGCWeak())
-        info.HasWeakBlockVariable = true;
-
       // Just use void* instead of a pointer to the byref type.
       QualType byRefPtrTy = C.VoidPtrTy;
 
@@ -650,22 +645,6 @@
     Builder.CreateBitCast(blockAddr,
                           ConvertType(blockInfo.getBlockExpr()->getType()));
 
-  // We must call objc_read_weak on the block literal itself if it closes
-  // on any __weak __block variables.  For some reason.
-  if (blockInfo.HasWeakBlockVariable) {
-    const llvm::Type *OrigTy = result->getType();
-
-    // Must cast argument to id*
-    const llvm::Type *ObjectPtrTy = 
-      ConvertType(CGM.getContext().getObjCIdType());
-    const llvm::Type *PtrObjectPtrTy = 
-      llvm::PointerType::getUnqual(ObjectPtrTy);
-    result = Builder.CreateBitCast(result, PtrObjectPtrTy);
-    result = CGM.getObjCRuntime().EmitObjCWeakRead(*this, result);
-
-    // Cast back to the original type.
-    result = Builder.CreateBitCast(result, OrigTy);
-  }
   return result;
 }
 

Modified: cfe/trunk/lib/CodeGen/CGBlocks.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.h?rev=125627&r1=125626&r2=125627&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.h (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.h Tue Feb 15 18:49:34 2011
@@ -173,9 +173,6 @@
   /// need to be run even in GC mode.
   bool HasCXXObject : 1;
 
-  /// HasWeakBlockVariable - True if block captures a weak __block variable.
-  bool HasWeakBlockVariable : 1;
-  
   const llvm::StructType *StructureType;
   const BlockExpr *Block;
   CharUnits BlockSize;

Modified: cfe/trunk/test/CodeGenObjC/objc2-weak-block-call.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/objc2-weak-block-call.m?rev=125627&r1=125626&r2=125627&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/objc2-weak-block-call.m (original)
+++ cfe/trunk/test/CodeGenObjC/objc2-weak-block-call.m Tue Feb 15 18:49:34 2011
@@ -1,7 +1,5 @@
-// RUN: %clang_cc1 -fblocks -fobjc-gc -triple x86_64-apple-darwin -S %s -o %t-64.s
-// RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s
-// RUN: %clang_cc1 -fblocks -fobjc-gc -triple i386-apple-darwin -S %s -o %t-32.s
-// RUN: FileCheck -check-prefix LP32 --input-file=%t-32.s %s
+// RUN: %clang_cc1 -fblocks -fobjc-gc -triple x86_64-apple-darwin -emit-llvm %s -o - | FileCheck -check-prefix LP64 %s
+// RUN: %clang_cc1 -fblocks -fobjc-gc -triple i386-apple-darwin -emit-llvm %s -o - | FileCheck -check-prefix LP64 %s
 
 @interface MyView
 - (void)MyView_sharedInit;
@@ -21,9 +19,6 @@
 }
 @end
 
-// CHECK-LP64: callq    _objc_read_weak
-// CHECK-LP64: callq    _objc_read_weak
-
-// CHECK-LP32: calll     L_objc_read_weak
-// CHECK-LP32: calll     L_objc_read_weak
+// CHECK-LP64: call i8* @objc_read_weak
+// CHECK-LP32: call i8* @objc_read_weak
 





More information about the cfe-commits mailing list