[cfe-commits] r158738 - in /cfe/trunk: lib/CodeGen/CGDecl.cpp test/CodeGenObjC/arc-blocks.m

Fariborz Jahanian fjahanian at apple.com
Tue Jun 19 13:53:26 PDT 2012


Author: fjahanian
Date: Tue Jun 19 15:53:26 2012
New Revision: 158738

URL: http://llvm.org/viewvc/llvm-project?rev=158738&view=rev
Log:
objc-arc: captured block variable accessed in its block literal
initializer need be null initialized before initializer takes
hold, just like any other initialized retainable object pointer. 
// rdar://11016025

Modified:
    cfe/trunk/lib/CodeGen/CGDecl.cpp
    cfe/trunk/test/CodeGenObjC/arc-blocks.m

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=158738&r1=158737&r2=158738&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Tue Jun 19 15:53:26 2012
@@ -490,6 +490,14 @@
 
     if (const DeclRefExpr *ref = dyn_cast<DeclRefExpr>(e))
       return (ref->getDecl() == &var);
+    if (const BlockExpr *be = dyn_cast<BlockExpr>(e)) {
+      const BlockDecl *block = be->getBlockDecl();
+      for (BlockDecl::capture_const_iterator i = block->capture_begin(),
+           e = block->capture_end(); i != e; ++i) {
+        if (i->getVariable() == &var)
+          return true;
+      }
+    }
   }
 
   for (Stmt::const_child_range children = s->children(); children; ++children)

Modified: cfe/trunk/test/CodeGenObjC/arc-blocks.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/arc-blocks.m?rev=158738&r1=158737&r2=158738&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/arc-blocks.m (original)
+++ cfe/trunk/test/CodeGenObjC/arc-blocks.m Tue Jun 19 15:53:26 2012
@@ -521,3 +521,14 @@
 void test15(int a) {
   test15_helper(^{ (void) a; }, ({ a; }));
 }
+
+// rdar://11016025
+void test16() {
+  void (^BLKVAR)(void) = ^{ BLKVAR(); };
+
+  // CHECK: define void @test16(
+  // CHECK: [[BLKVAR:%.*]]  = alloca void ()*, align 8
+  // CHECK-NEXT:  [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]],
+  // CHECK-NEXT:  [[SLOTREL:%.*]] = getelementptr inbounds [[BLOCK_T]]* [[BLOCK]], i32 0, i32 5
+  // CHECK-NEXT:  store void ()* null, void ()** [[BLKVAR]], align 8
+}





More information about the cfe-commits mailing list