]> granicus.if.org Git - clang/commit
[analyzer] Track whether an ObjC for-in loop had zero iterations.
authorJordan Rose <jordan_rose@apple.com>
Fri, 8 Nov 2013 01:15:35 +0000 (01:15 +0000)
committerJordan Rose <jordan_rose@apple.com>
Fri, 8 Nov 2013 01:15:35 +0000 (01:15 +0000)
commit219103d76a10b35b5a1e8d2b6737cf724a7cfee7
treebb0e8c01b3d6063b5a07b829ba40413f72ccb05f
parent64cc0c37f78719f905029a9099445c214cb40ce3
[analyzer] Track whether an ObjC for-in loop had zero iterations.

An Objective-C for-in loop will have zero iterations if the collection is
empty. Previously, we could only detect this case if the program asked for
the collection's -count /before/ the for-in loop. Now, the analyzer
distinguishes for-in loops that had zero iterations from those with at
least one, and can use this information to constrain the result of calling
-count after the loop.

In order to make this actually useful, teach the checker that methods on
NSArray, NSDictionary, and the other immutable collection classes don't
change the count.

<rdar://problem/14992886>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194235 91177308-0d34-0410-b5e6-96231b3b80d8
lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
test/Analysis/objc-for.m