[PATCH] [analyzer] RetainCountChecker: be forgiving when ivars are accessed directly

Jordan Rose jordan_rose at apple.com
Mon Jan 5 09:34:58 PST 2015


Hi zaks.anna,

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

http://reviews.llvm.org/D6846

Files:
  lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
  test/Analysis/properties.m
  test/Analysis/retain-release-path-notes.m

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D6846.17807.patch
Type: text/x-patch
Size: 113962 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150105/5b67780b/attachment.bin>


More information about the cfe-commits mailing list