r318552 - [ObjC][ARC] Honor noescape attribute for -Warc-retain-cycles
Alex Lorenz via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 17 12:44:25 PST 2017
Author: arphaman
Date: Fri Nov 17 12:44:25 2017
New Revision: 318552
URL: http://llvm.org/viewvc/llvm-project?rev=318552&view=rev
Log:
[ObjC][ARC] Honor noescape attribute for -Warc-retain-cycles
rdar://35409566
Differential Revision: https://reviews.llvm.org/D40141
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/SemaObjC/warn-retain-cycle.m
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=318552&r1=318551&r2=318552&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Nov 17 12:44:25 2017
@@ -11652,9 +11652,15 @@ void Sema::checkRetainCycles(ObjCMessage
}
// 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.
Modified: cfe/trunk/test/SemaObjC/warn-retain-cycle.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/warn-retain-cycle.m?rev=318552&r1=318551&r2=318552&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/warn-retain-cycle.m (original)
+++ cfe/trunk/test/SemaObjC/warn-retain-cycle.m Fri Nov 17 12:44:25 2017
@@ -198,3 +198,15 @@ __block void(^myBlock)(void) = ^{
};
}
+
+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.
+ }];
+}
More information about the cfe-commits
mailing list