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