arphaman created this revision. This patch ensures that -Warc-retain-cycles doesn't warn about captures in blocks that are passed into parameters that have a `noescape` attribute.
Repository: rL LLVM https://reviews.llvm.org/D40141 Files: lib/Sema/SemaChecking.cpp test/SemaObjC/warn-retain-cycle.m Index: test/SemaObjC/warn-retain-cycle.m =================================================================== --- test/SemaObjC/warn-retain-cycle.m +++ test/SemaObjC/warn-retain-cycle.m @@ -198,3 +198,15 @@ }; } + +typedef void (^a_block_t)(void); + +@interface HonorNoEscape +- (void)addStuffUsingBlock:(__attribute__((noescape)) a_block_t)block; +@end + +void testNoEscape(HonorNoEscape *obj) { + [obj addStuffUsingBlock:^{ + (void)obj; // ok. + }]; +} Index: lib/Sema/SemaChecking.cpp =================================================================== --- lib/Sema/SemaChecking.cpp +++ lib/Sema/SemaChecking.cpp @@ -11652,9 +11652,14 @@ } // Check whether the receiver is captured by any of the arguments. - for (unsigned i = 0, e = msg->getNumArgs(); i != e; ++i) + const ObjCMethodDecl *MD = msg->getMethodDecl(); + for (unsigned i = 0, e = msg->getNumArgs(); i != e; ++i) { + // noescape blocks should not be retained by the method. + if (MD && MD->parameters()[i]->hasAttr<NoEscapeAttr>()) + continue; if (Expr *capturer = findCapturingExpr(*this, msg->getArg(i), owner)) return diagnoseRetainCycle(*this, capturer, owner); + } } /// Check a property assign to see if it's likely to cause a retain cycle.
Index: test/SemaObjC/warn-retain-cycle.m =================================================================== --- test/SemaObjC/warn-retain-cycle.m +++ test/SemaObjC/warn-retain-cycle.m @@ -198,3 +198,15 @@ }; } + +typedef void (^a_block_t)(void); + +@interface HonorNoEscape +- (void)addStuffUsingBlock:(__attribute__((noescape)) a_block_t)block; +@end + +void testNoEscape(HonorNoEscape *obj) { + [obj addStuffUsingBlock:^{ + (void)obj; // ok. + }]; +} Index: lib/Sema/SemaChecking.cpp =================================================================== --- lib/Sema/SemaChecking.cpp +++ lib/Sema/SemaChecking.cpp @@ -11652,9 +11652,14 @@ } // Check whether the receiver is captured by any of the arguments. - for (unsigned i = 0, e = msg->getNumArgs(); i != e; ++i) + const ObjCMethodDecl *MD = msg->getMethodDecl(); + for (unsigned i = 0, e = msg->getNumArgs(); i != e; ++i) { + // noescape blocks should not be retained by the method. + if (MD && MD->parameters()[i]->hasAttr<NoEscapeAttr>()) + continue; if (Expr *capturer = findCapturingExpr(*this, msg->getArg(i), owner)) return diagnoseRetainCycle(*this, capturer, owner); + } } /// Check a property assign to see if it's likely to cause a retain cycle.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits