]> granicus.if.org Git - clang/commit
[analyzer] An ObjC for-in loop runs 0 times if the collection is nil.
authorJordan Rose <jordan_rose@apple.com>
Fri, 26 Apr 2013 21:43:01 +0000 (21:43 +0000)
committerJordan Rose <jordan_rose@apple.com>
Fri, 26 Apr 2013 21:43:01 +0000 (21:43 +0000)
commit5d2e4e1f9ed87ea26295e891acf7e5a3b106f194
tree9738a635b234b8857d5b1a96ebafee1dfc4e7e53
parent5e6c06bc7deaaefe130b730032a9acb9cd38bf0c
[analyzer] An ObjC for-in loop runs 0 times if the collection is nil.

In an Objective-C for-in loop "for (id element in collection) {}", the loop
will run 0 times if the collection is nil. This is because the for-in loop
is implemented using a protocol method that returns 0 when there are no
elements to iterate, and messages to nil will result in a 0 return value.

At some point we may want to actually model this message send, but for now
we may as well get the nil case correct, and avoid the false positives that
would come with this case.

<rdar://problem/13744632>

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