Skip to content

Commit

Permalink
[analyzer] RetainCountChecker: don't try to track ivars known to be nil.
Browse files Browse the repository at this point in the history
We expect in general that any nil value has no retain count information
associated with it; violating this results in unexpected state unification
/later/ when we decide to throw the information away. Unexpectedly caching
out can lead to an assertion failure or crash.

rdar://problem/19862648

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@229934 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
jrose-apple committed Feb 19, 2015
1 parent 99fa97a commit 5bf523b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2852,7 +2852,7 @@ void RetainCountChecker::checkPostStmt(const ObjCIvarRefExpr *IRE,

ProgramStateRef State = C.getState();
SymbolRef Sym = State->getSVal(*IVarLoc).getAsSymbol();
if (!Sym)
if (!Sym || !wasLoadedFromIvar(Sym))
return;

// Accessing an ivar directly is unusual. If we've done that, be more
Expand All @@ -2867,7 +2867,9 @@ void RetainCountChecker::checkPostStmt(const ObjCIvarRefExpr *IRE,
else
return;

if (!wasLoadedFromIvar(Sym))
// If the value is already known to be nil, don't bother tracking it.
ConstraintManager &CMgr = State->getConstraintManager();
if (CMgr.isNull(State, Sym).isConstrainedTrue())
return;

if (const RefVal *RV = getRefBinding(State, Sym)) {
Expand Down
15 changes: 15 additions & 0 deletions test/Analysis/properties.m
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,21 @@ - (void)testAssignIvarOnlyOkay:(id)newValue {
[_ivarOnly release]; // no-warning
}

// rdar://problem/19862648
- (void)establishIvarIsNilDuringLoops {
extern id getRandomObject();

int i = 4; // Must be at least 4 to trigger the bug.
while (--i) {
id x = 0;
if (getRandomObject())
x = _ivarOnly;
if (!x)
x = getRandomObject();
[x myMethod];
}
}

@end
#endif // non-ARC

0 comments on commit 5bf523b

Please sign in to comment.