[PATCH] D40141: [ObjC][ARC] Honor noescape attribute for -Warc-retain-cycles

Alex Lorenz via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 17 12:46:32 PST 2017


This revision was automatically updated to reflect the committed changes.
arphaman marked an inline comment as done.
Closed by commit rL318552: [ObjC][ARC] Honor noescape attribute for -Warc-retain-cycles (authored by arphaman).

Changed prior to commit:
  https://reviews.llvm.org/D40141?vs=123211&id=123401#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40141

Files:
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/test/SemaObjC/warn-retain-cycle.m


Index: cfe/trunk/test/SemaObjC/warn-retain-cycle.m
===================================================================
--- cfe/trunk/test/SemaObjC/warn-retain-cycle.m
+++ cfe/trunk/test/SemaObjC/warn-retain-cycle.m
@@ -198,3 +198,15 @@
    };
 
 }
+
+typedef void (^a_block_t)(void);
+
+ at interface HonorNoEscape
+- (void)addStuffUsingBlock:(__attribute__((noescape)) a_block_t)block;
+ at end
+
+void testNoEscape(HonorNoEscape *obj) {
+  [obj addStuffUsingBlock:^{
+    (void)obj; // ok.
+  }];
+}
Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -11652,9 +11652,15 @@
   }
 
   // Check whether the receiver is captured by any of the arguments.
-  for (unsigned i = 0, e = msg->getNumArgs(); i != e; ++i)
-    if (Expr *capturer = findCapturingExpr(*this, msg->getArg(i), owner))
+  const ObjCMethodDecl *MD = msg->getMethodDecl();
+  for (unsigned i = 0, e = msg->getNumArgs(); i != e; ++i) {
+    if (Expr *capturer = findCapturingExpr(*this, msg->getArg(i), owner)) {
+      // noescape blocks should not be retained by the method.
+      if (MD && MD->parameters()[i]->hasAttr<NoEscapeAttr>())
+        continue;
       return diagnoseRetainCycle(*this, capturer, owner);
+    }
+  }
 }
 
 /// Check a property assign to see if it's likely to cause a retain cycle.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40141.123401.patch
Type: text/x-patch
Size: 1413 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171117/307b9546/attachment.bin>


More information about the cfe-commits mailing list