Ted Kremenek | 565e465 | 2010-02-05 02:06:54 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=basic -verify %s |
| 2 | // RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=region -verify %s |
Ted Kremenek | d54ae2a | 2008-06-16 21:15:29 +0000 | [diff] [blame] | 3 | |
| 4 | //===----------------------------------------------------------------------===// |
| 5 | // The following code is reduced using delta-debugging from |
| 6 | // Foundation.h (Mac OS X). |
| 7 | // |
| 8 | // It includes the basic definitions for the test cases below. |
| 9 | // Not directly including Foundation.h directly makes this test case |
| 10 | // both svelte and portable to non-Mac platforms. |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | typedef signed char BOOL; |
| 14 | typedef unsigned int NSUInteger; |
| 15 | typedef struct _NSZone NSZone; |
| 16 | @class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; |
| 17 | @protocol NSObject - (BOOL)isEqual:(id)object; @end |
| 18 | @protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end |
| 19 | @protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone; @end |
| 20 | @protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end |
| 21 | @interface NSObject <NSObject> {} @end |
| 22 | @class NSString, NSData; |
| 23 | @class NSString, NSData, NSMutableData, NSMutableDictionary, NSMutableArray; |
| 24 | typedef struct {} NSFastEnumerationState; |
| 25 | @protocol NSFastEnumeration |
| 26 | - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len; |
| 27 | @end |
| 28 | @class NSData, NSIndexSet, NSString, NSURL; |
| 29 | @interface NSArray : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration> |
| 30 | - (NSUInteger)count; |
| 31 | @end |
| 32 | @interface NSArray (NSArrayCreation) |
| 33 | + (id)array; |
| 34 | - (NSUInteger)length; |
| 35 | - (void)addObject:(id)object; |
| 36 | @end |
| 37 | extern NSString * const NSUndoManagerCheckpointNotification; |
| 38 | |
| 39 | //===----------------------------------------------------------------------===// |
| 40 | // Test cases. |
| 41 | //===----------------------------------------------------------------------===// |
| 42 | |
| 43 | unsigned f1() { |
| 44 | NSString *aString; |
Ted Kremenek | c79d7d4 | 2009-11-21 01:25:37 +0000 | [diff] [blame] | 45 | return [aString length]; // expected-warning {{Receiver in message expression is a garbage value}} |
Ted Kremenek | d54ae2a | 2008-06-16 21:15:29 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | unsigned f2() { |
| 49 | NSString *aString = 0; |
| 50 | return [aString length]; // no-warning |
| 51 | } |
| 52 | |
| 53 | void f3() { |
| 54 | NSMutableArray *aArray = [NSArray array]; |
| 55 | NSString *aString; |
| 56 | [aArray addObject:aString]; // expected-warning {{Pass-by-value argument in message expression is undefined.}} |
| 57 | } |