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