diff options
author | Ted Kremenek <kremenek@apple.com> | 2011-12-01 00:59:21 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2011-12-01 00:59:21 +0000 |
commit | 764d63ad94e43dfa0939b5924b00c54fd07b7ff5 (patch) | |
tree | 660e5af2d770e6c98b270b5ec7c8d2baadd2b27a | |
parent | 85825aebc96ed4f84f5a1c7c141673d782a6d32b (diff) | |
download | bcm5719-llvm-764d63ad94e43dfa0939b5924b00c54fd07b7ff5.tar.gz bcm5719-llvm-764d63ad94e43dfa0939b5924b00c54fd07b7ff5.zip |
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>.
llvm-svn: 145548
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 8 | ||||
-rw-r--r-- | clang/test/SemaObjC/warn-retain-cycle.m | 34 |
2 files changed, 41 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index ec36963ed61..0d640a8c123 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -4533,8 +4533,14 @@ static bool isSetterLikeSelector(Selector sel) { 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; diff --git a/clang/test/SemaObjC/warn-retain-cycle.m b/clang/test/SemaObjC/warn-retain-cycle.m index 596858f83a3..a05e663c092 100644 --- a/clang/test/SemaObjC/warn-retain-cycle.m +++ b/clang/test/SemaObjC/warn-retain-cycle.m @@ -89,3 +89,37 @@ void test2_helper(id); }; } @end + + +@interface NSOperationQueue {} +- (void)addOperationWithBlock:(void (^)(void))block; +- (void)addSomethingElse:(void (^)(void))block; + +@end + +@interface Test3 { + NSOperationQueue *myOperationQueue; + unsigned count; +} +@end +void doSomething(unsigned v); +@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); + } + }]; +} +@end + |