This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] RetainCount: When diagnosing overrelease, mention if it's coming from a nested block.
AbandonedPublic

Authored by NoQ on Aug 15 2017, 8:55 AM.

Details

Summary

RetainCountChecker's warning message "Incorrect decrement of the reference count of an object that is not owned at this point by the caller" does not explicitly mention the caller, which may be confusing when there is a nested block, especially when the block is hard to notice. It should be obvious to which caller it refers. The patch tries to improve on that.

By the way, plist-based tests in retain-release.m are disabled since r163536 (~2012), and need to be updated. It's trivial to re-enable them but annoying to maintain - would we prefer to re-enable or delete them or replace with -analyzer-output=text tests?

Diff Detail

Event Timeline

NoQ created this revision.Aug 15 2017, 8:55 AM
dcoughlin edited edge metadata.Aug 16 2017, 9:12 AM

By the way, plist-based tests in retain-release.m are disabled since r163536 (~2012), and need to be updated. It's trivial to re-enable them but annoying to maintain - would we prefer to re-enable or delete them or replace with -analyzer-output=text tests?

This is rdar://problem/33514142

My preference would be to factor out/re-target some specific tests into their own file and check that with -verify + -analyzer-output=text and with plist comparisons

lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
89

Is it possible to detect this from the location context in RetainCountChecker::processNonLeakError() rather than encoding it in the analysis state? This would avoid a multiplicity of 'ByBlock' kinds.

I forgot to say this looks like a nice usability improvement!

NoQ updated this revision to Diff 113102.Aug 29 2017, 9:12 AM
NoQ marked an inline comment as done.

Avoid creating a new RefVal kind.

By the way, plist-based tests in retain-release.m are disabled since r163536 (~2012), and need to be updated. It's trivial to re-enable them but annoying to maintain - would we prefer to re-enable or delete them or replace with -analyzer-output=text tests?

My preference would be to factor out/re-target some specific tests into their own file and check that with -verify + -analyzer-output=text and with plist comparisons

Hmm, which specific tests do you have in mind? And is it worth it to try to recover the intended arrows in plists from the old plist tests?

NoQ planned changes to this revision.Sep 1 2017, 6:51 AM

This is all wrong. While RetainCountChecker is more function-local than, say, MallocChecker, we still can't say for sure that it is the bottom frame's function (or block) that should be owning the object in this case. Ideally it should, but that's not the pattern that the checker is de facto trying to find. The checker is usually fine seeing a pointer allocated in a top function and released in a sub-block. If the bottom frame is over-releasing, we'd warn, but it wouldn't be simply because the bottom frame is over-releasing, so mentioning the particular stack frame may end up being misleading.

NoQ abandoned this revision.Oct 13 2017, 2:44 AM