This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] Warn on use of 'self' after call to to [super dealloc].
ClosedPublic

Authored by dcoughlin on Feb 22 2016, 3:47 PM.

Details

Summary

Referring to 'self' after a call to [super dealloc] is a use-after-free in Objective-C because NSObject's -dealloc frees the memory pointed to by self. This patch extends the ObjCSuperDeallocChecker to catch this error.

rdar://problem/6953275

Diff Detail

Repository
rL LLVM

Event Timeline

dcoughlin updated this revision to Diff 48747.Feb 22 2016, 3:47 PM
dcoughlin retitled this revision from to [analyzer] Warn on use of 'self' after call to to [super dealloc]..
dcoughlin updated this object.
dcoughlin added a reviewer: zaks.anna.
dcoughlin added a subscriber: cfe-commits.
dcoughlin updated this object.Feb 22 2016, 3:49 PM
dcoughlin added a subscriber: ddkilzer.
zaks.anna added inline comments.Feb 24 2016, 10:40 PM
lib/StaticAnalyzer/Checkers/ObjCSuperDeallocChecker.cpp
165 ↗(On Diff #48747)

Does "has been freed" sound better?

test/Analysis/DeallocUseAfterFreeErrors.m
59 ↗(On Diff #48747)

Would it be possible to provide a more presice error message here? Specifically, we refer to 'self' here but the reference is implicit. I guess we could say something like "accessing an instance variable after the object has been freed". Would that require extra checking to ensure that we are indeed accessing a member in checkLocation?

This revision was automatically updated to reflect the committed changes.
dcoughlin marked an inline comment as done.
dcoughlin added inline comments.Feb 25 2016, 3:41 PM
lib/StaticAnalyzer/Checkers/ObjCSuperDeallocChecker.cpp
165 ↗(On Diff #48747)

Yes, changed it.

test/Analysis/DeallocUseAfterFreeErrors.m
59 ↗(On Diff #48747)

I've updated this to be "use of instance variable '_ivar' after the instance has been freed with call to [super dealloc]".