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