Jordan Rose | 1895a0a | 2012-06-11 16:40:41 +0000 | [diff] [blame^] | 1 | // RUN: %clang_cc1 -analyze -analyzer-checker=osx.cocoa.Loops,debug.ExprInspection -verify |
| 2 | |
| 3 | void clang_analyzer_eval(int); |
| 4 | |
| 5 | #define nil ((id)0) |
| 6 | |
| 7 | @protocol NSFastEnumeration |
| 8 | - (int)countByEnumeratingWithState:(void *)state objects:(id *)objects count:(unsigned)count; |
| 9 | @end |
| 10 | |
| 11 | @interface NSObject |
| 12 | + (instancetype)testObject; |
| 13 | @end |
| 14 | |
| 15 | @interface NSEnumerator <NSFastEnumeration> |
| 16 | @end |
| 17 | |
| 18 | @interface NSArray : NSObject <NSFastEnumeration> |
| 19 | - (NSEnumerator *)objectEnumerator; |
| 20 | @end |
| 21 | |
| 22 | @interface NSDictionary : NSObject <NSFastEnumeration> |
| 23 | @end |
| 24 | |
| 25 | @interface NSMutableDictionary : NSDictionary |
| 26 | @end |
| 27 | |
| 28 | @interface NSSet : NSObject <NSFastEnumeration> |
| 29 | @end |
| 30 | |
| 31 | @interface NSPointerArray : NSObject <NSFastEnumeration> |
| 32 | @end |
| 33 | |
| 34 | void test() { |
| 35 | id x; |
| 36 | for (x in [NSArray testObject]) |
| 37 | clang_analyzer_eval(x != nil); // expected-warning{{TRUE}} |
| 38 | |
| 39 | for (x in [NSMutableDictionary testObject]) |
| 40 | clang_analyzer_eval(x != nil); // expected-warning{{TRUE}} |
| 41 | |
| 42 | for (x in [NSSet testObject]) |
| 43 | clang_analyzer_eval(x != nil); // expected-warning{{TRUE}} |
| 44 | |
| 45 | for (x in [[NSArray testObject] objectEnumerator]) |
| 46 | clang_analyzer_eval(x != nil); // expected-warning{{TRUE}} |
| 47 | |
| 48 | for (x in [NSPointerArray testObject]) |
| 49 | clang_analyzer_eval(x != nil); // expected-warning{{UNKNOWN}} |
| 50 | } |
| 51 | |
| 52 | void testWithVarInFor() { |
| 53 | for (id x in [NSArray testObject]) |
| 54 | clang_analyzer_eval(x != nil); // expected-warning{{TRUE}} |
| 55 | for (id x in [NSPointerArray testObject]) |
| 56 | clang_analyzer_eval(x != nil); // expected-warning{{UNKNOWN}} |
| 57 | } |
| 58 | |