diff options
| author | Jordan Rose <jordan_rose@apple.com> | 2012-06-15 18:19:52 +0000 |
|---|---|---|
| committer | Jordan Rose <jordan_rose@apple.com> | 2012-06-15 18:19:52 +0000 |
| commit | 95dfae824ef82ad51ba5f6b3a1681f2ef5febc45 (patch) | |
| tree | 2e448b8c22bb27bd63d355366ea7c6cc3fde3246 /clang | |
| parent | 2684c68ddc2f19c34ab0ed280c1d3238a1279e73 (diff) | |
| download | bcm5719-llvm-95dfae824ef82ad51ba5f6b3a1681f2ef5febc45.tar.gz bcm5719-llvm-95dfae824ef82ad51ba5f6b3a1681f2ef5febc45.zip | |
[analyzer] RetainCount: don't track objects init'd with a delegate
We already didn't track objects that have delegates or callbacks or
objects that are passed through void * "context pointers". It's a
not-uncommon pattern to release the object in its callback, and so
the leak message we give is not very helpful.
llvm-svn: 158532
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp | 13 | ||||
| -rw-r--r-- | clang/test/Analysis/delegates.m | 18 |
2 files changed, 27 insertions, 4 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp index 99243d2b141..fc21a1ba7d7 100644 --- a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp @@ -1351,10 +1351,15 @@ RetainSummaryManager::getStandardMethodSummary(const ObjCMethodDecl *MD, // because the reference count is quite possibly handled by a delegate // method. if (S.isKeywordSelector()) { - const std::string &str = S.getAsString(); - assert(!str.empty()); - if (StrInStrNoCase(str, "delegate:") != StringRef::npos) - ReceiverEff = StopTracking; + for (unsigned i = 0, e = S.getNumArgs(); i != e; ++i) { + StringRef Slot = S.getNameForSlot(i); + if (Slot.substr(Slot.size() - 8).equals_lower("delegate")) { + if (ResultEff == ObjCInitRetE) + ResultEff = RetEffect::MakeNoRet(); + else + ReceiverEff = StopTracking; + } + } } if (ScratchArgs.isEmpty() && ReceiverEff == DoNothing && diff --git a/clang/test/Analysis/delegates.m b/clang/test/Analysis/delegates.m index 8f42b83b0ee..7a86671a2f6 100644 --- a/clang/test/Analysis/delegates.m +++ b/clang/test/Analysis/delegates.m @@ -111,3 +111,21 @@ extern void *_NSConstantStringClassReference; } @end + +@interface ObjectThatRequiresDelegate : NSObject +- (id)initWithDelegate:(id)delegate; +- (id)initWithNumber:(int)num delegate:(id)delegate; +@end + + +@interface DelegateRequirerTest +@end +@implementation DelegateRequirerTest + +- (void)test { + (void)[[ObjectThatRequiresDelegate alloc] initWithDelegate:self]; + (void)[[ObjectThatRequiresDelegate alloc] initWithNumber:0 delegate:self]; + // no leak warnings -- these objects could be released in callback methods +} + +@end |

