]> granicus.if.org Git - clang/commitdiff
objective-C ARC; detect and warn on retain cycle when
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 31 Aug 2012 20:04:47 +0000 (20:04 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 31 Aug 2012 20:04:47 +0000 (20:04 +0000)
property-dot syntax is used on an object whose
capture causes retain cycle. // rdar://11702054

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

lib/Sema/SemaChecking.cpp
test/SemaObjC/warn-retain-cycle.m

index 137f3e1a5e3008d39b9fe0900fc575e229a4cfdd..6d6461136b18158c43ac3f4a2481834e305555a3 100644 (file)
@@ -5253,6 +5253,12 @@ namespace {
       if (block->getBlockDecl()->capturesVariable(Variable))
         Visit(block->getBlockDecl()->getBody());
     }
+    
+    void VisitOpaqueValueExpr(OpaqueValueExpr *OVE) {
+      if (Capturer) return;
+      if (OVE->getSourceExpr())
+        Visit(OVE->getSourceExpr());
+    }
   };
 }
 
index 00fd234a0c09ccec7235a7d0815d91fd619876fa..44d450a3101c7f10641c0ba71df885b74d80bd6a 100644 (file)
@@ -24,6 +24,10 @@ void test0(Test0 *x) {
   [weakx addBlock: ^{ [x actNow]; }];
   [weakx setBlock: ^{ [x actNow]; }];
   weakx.block = ^{ [x actNow]; };
+
+  // rdar://11702054
+  x.block = ^{ (void)x.actNow; };  // expected-warning {{capturing 'x' strongly in this block is likely to lead to a retain cycle}} \
+                                   // expected-note {{block will be retained by the captured object}}
 }
 
 @interface BlockOwner