]> granicus.if.org Git - clang/commit
[analyzer] RetainCountChecker: be forgiving when ivars are accessed directly.
authorJordan Rose <jordan_rose@apple.com>
Wed, 4 Feb 2015 19:24:52 +0000 (19:24 +0000)
committerJordan Rose <jordan_rose@apple.com>
Wed, 4 Feb 2015 19:24:52 +0000 (19:24 +0000)
commitd23154687daef83038283730288af4dce3303814
tree56f48e4d4fb4c55d0881ab5ecbf40e6e2e25ec3d
parent0f709c8ce3a6b62463761053df447e4655f61bb3
[analyzer] RetainCountChecker: be forgiving when ivars are accessed directly.

A refinement of r204730, itself a refinement of r198953, to better handle
cases where an object is accessed both through a property getter and
through direct ivar access. An object accessed through a property should
always be treated as +0, i.e. not owned by the caller. However, an object
accessed through an ivar may be at +0 or at +1, depending on whether the
ivar is a strong reference. Outside of ARC, we don't always have that
information.

The previous attempt would clear out the +0 provided by a getter, but only
if that +0 hadn't already participated in other retain counting operations.
(That is, "self.foo" is okay, but "[[self.foo retain] autorelease]" is
problematic.) This turned out to not be good enough when our synthesized
getters get involved.

This commit drops the notion of "overridable" reference counting and instead
just tracks whether a value ever came from a (strong) ivar. If it has, we
allow one more release than we otherwise would. This has the added benefit
of being able to catch /some/ overreleases of instance variables, though
it's not likely to come up in practice.

We do still get some false negatives because we currently throw away
refcount state upon assigning a value into an ivar. We should probably
improve on that in the future, especially once we synthesize setters as
well as getters.

rdar://problem/18075108

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@228174 91177308-0d34-0410-b5e6-96231b3b80d8
lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
test/Analysis/properties.m
test/Analysis/retain-release-path-notes.m