]> granicus.if.org Git - clang/commitdiff
objc-arc: captured block variable accessed in its block literal
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 19 Jun 2012 20:53:26 +0000 (20:53 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 19 Jun 2012 20:53:26 +0000 (20:53 +0000)
initializer need be null initialized before initializer takes
hold, just like any other initialized retainable object pointer.
// rdar://11016025

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

lib/CodeGen/CGDecl.cpp
test/CodeGenObjC/arc-blocks.m

index 4d4b57904c45357673483f86c5aa5f228af4f5c0..ff803c612fb44399f3ea0056a1db54278da290f6 100644 (file)
@@ -490,6 +490,14 @@ static bool isAccessedBy(const VarDecl &var, const Stmt *s) {
 
     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)
index 06acf01ce0f739e001af88bc6cdd11a5ceefa786..1092a8712d8b578e7e9dafb84a2f3e1c27118d90 100644 (file)
@@ -521,3 +521,14 @@ void test15_helper(void (^block)(void), int x);
 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
+}