forked from OSchip/llvm-project
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
This commit is contained in:
parent
85825aebc9
commit
764d63ad94
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue