[cfe-commits] r145548 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/SemaObjC/warn-retain-cycle.m
Ted Kremenek
kremenek at apple.com
Wed Nov 30 16:59:21 PST 2011
Author: kremenek
Date: Wed Nov 30 18:59:21 2011
New Revision: 145548
URL: http://llvm.org/viewvc/llvm-project?rev=145548&view=rev
Log:
Specially whitelist the selector 'addOperationWithBlock:' for the retain-cycle checking in -Warc-retain-cycles. This commonly
is hit by users using NSOperationQueue. Fixes <rdar://problem/10465721>.
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=145548&r1=145547&r2=145548&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Nov 30 18:59:21 2011
@@ -4533,8 +4533,14 @@
StringRef str = sel.getNameForSlot(0);
while (!str.empty() && str.front() == '_') str = str.substr(1);
- if (str.startswith("set") || str.startswith("add"))
+ if (str.startswith("set"))
str = str.substr(3);
+ else if (str.startswith("add")) {
+ // Specially whitelist 'addOperationWithBlock:'.
+ if (sel.getNumArgs() == 1 && str.startswith("addOperationWithBlock"))
+ return false;
+ str = str.substr(3);
+ }
else
return false;
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=145548&r1=145547&r2=145548&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/warn-retain-cycle.m (original)
+++ cfe/trunk/test/SemaObjC/warn-retain-cycle.m Wed Nov 30 18:59:21 2011
@@ -89,3 +89,37 @@
};
}
@end
+
+
+ at interface NSOperationQueue {}
+- (void)addOperationWithBlock:(void (^)(void))block;
+- (void)addSomethingElse:(void (^)(void))block;
+
+ at end
+
+ at interface Test3 {
+ NSOperationQueue *myOperationQueue;
+ unsigned count;
+}
+ at end
+void doSomething(unsigned v);
+ at implementation Test3
+- (void) test {
+ // 'addOperationWithBlock:' is specifically whitelisted.
+ [myOperationQueue addOperationWithBlock:^() { // no-warning
+ if (count > 20) {
+ doSomething(count);
+ }
+ }];
+}
+- (void) test_positive {
+ // Sanity check that we are really whitelisting 'addOperationWithBlock:' and not doing
+ // something funny.
+ [myOperationQueue addSomethingElse:^() { // expected-note {{block will be retained by an object strongly retained by the captured object}}
+ if (count > 20) { // expected-warning {{capturing 'self' strongly in this block is likely to lead to a retain cycle}}
+ doSomething(count);
+ }
+ }];
+}
+ at end
+
More information about the cfe-commits
mailing list