r229934 - [analyzer] RetainCountChecker: don't try to track ivars known to be nil.
Jordan Rose
jordan_rose at apple.com
Thu Feb 19 15:57:04 PST 2015
Author: jrose
Date: Thu Feb 19 17:57:04 2015
New Revision: 229934
URL: http://llvm.org/viewvc/llvm-project?rev=229934&view=rev
Log:
[analyzer] RetainCountChecker: don't try to track ivars known to be nil.
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
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
cfe/trunk/test/Analysis/properties.m
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp?rev=229934&r1=229933&r2=229934&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp Thu Feb 19 17:57:04 2015
@@ -2852,7 +2852,7 @@ void RetainCountChecker::checkPostStmt(c
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
@@ -2867,7 +2867,9 @@ void RetainCountChecker::checkPostStmt(c
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)) {
Modified: cfe/trunk/test/Analysis/properties.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/properties.m?rev=229934&r1=229933&r2=229934&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/properties.m (original)
+++ cfe/trunk/test/Analysis/properties.m Thu Feb 19 17:57:04 2015
@@ -513,6 +513,21 @@ void testOpaqueConsistency(OpaqueIntWrap
[_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
More information about the cfe-commits
mailing list