1 // RUN: %clang_analyze_cc1 %s -verify \
2 // RUN: -Wno-objc-root-class \
3 // RUN: -analyzer-checker=core \
4 // RUN: -analyzer-config core.CallAndMessage:FunctionPointer=false \
5 // RUN: -analyzer-config core.CallAndMessage:ParameterCount=false \
6 // RUN: -analyzer-config core.CallAndMessage:CXXThisMethodCall=false \
7 // RUN: -analyzer-config core.CallAndMessage:CXXDeallocationArg=false \
8 // RUN: -analyzer-config core.CallAndMessage:ArgInitializedness=false \
9 // RUN: -analyzer-config core.CallAndMessage:ArgPointeeInitializedness=false \
10 // RUN: -analyzer-config core.CallAndMessage:NilReceiver=false \
11 // RUN: -analyzer-config core.CallAndMessage:UndefReceiver=true \
12 // RUN: -analyzer-output=plist -o %t.plist
13 // RUN: cat %t.plist | FileCheck %s
15 //===----------------------------------------------------------------------===//
16 // The following code is reduced using delta-debugging from
17 // Foundation.h (Mac OS X).
19 // It includes the basic definitions for the test cases below.
20 // Not directly including Foundation.h directly makes this test case
21 // both svelte and portable to non-Mac platforms.
22 //===----------------------------------------------------------------------===//
24 typedef signed char BOOL;
25 typedef unsigned int NSUInteger;
26 typedef struct _NSZone NSZone;
27 @class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
29 - (BOOL)isEqual:(id)object;
32 - (id)copyWithZone:(NSZone *)zone;
34 @protocol NSMutableCopying
35 - (id)mutableCopyWithZone:(NSZone *)zone;
38 - (void)encodeWithCoder:(NSCoder *)aCoder;
40 @interface NSObject <NSObject> {
43 @class NSString, NSData;
44 @class NSString, NSData, NSMutableData, NSMutableDictionary, NSMutableArray;
46 } NSFastEnumerationState;
47 @protocol NSFastEnumeration
48 - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len;
50 @class NSData, NSIndexSet, NSString, NSURL;
51 @interface NSArray : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>
54 @interface NSArray (NSArrayCreation)
57 - (void)addObject:(id)object;
59 extern NSString *const NSUndoManagerCheckpointNotification;
61 //===----------------------------------------------------------------------===//
63 //===----------------------------------------------------------------------===//
67 return [aString length]; // expected-warning {{Receiver in message expression is an uninitialized value [core.CallAndMessage]}}
70 // TODO: If this hash ever changes, turn core.CallAndMessage:UndefReceiver from
71 // a checker option into a checker, as described in the CallAndMessage comments!
72 // CHECK: <key>issue_hash_content_of_line_in_context</key>
73 // CHECK-SAME: <string>29873175e1cc0a98f7040057279925a0</string>
75 @interface RDar9241180
76 @property(readwrite, assign) id x;
77 - (id)testAnalyzer1:(int)y;
80 @implementation RDar9241180
82 - (id)testAnalyzer1:(int)y {
84 if (y && o.x) // expected-warning {{Property access on an uninitialized object pointer [core.CallAndMessage]}}
87 // TODO: If this hash ever changes, turn core.CallAndMessage:UndefReceiver from
88 // a checker option into a checker, as described in the CallAndMessage comments!
89 // CHECK: <key>issue_hash_content_of_line_in_context</key>
90 // CHECK-SAME: <string>00ddd30796a283de33e662da8449c796</string>
92 return o; // expected-warning {{Undefined or garbage value returned to caller [core.uninitialized.UndefReturn]}}
96 // CHECK: <key>issue_hash_content_of_line_in_context</key>
97 // CHECK-SAME: <string>8d468e24df7d887f4182bf49f5dd8b71</string>
99 typedef signed char BOOL;
100 typedef unsigned int NSUInteger;
102 @interface Subscriptable : NSObject
103 - (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)index;
104 - (id)objectAtIndexedSubscript:(NSUInteger)index;
106 - (void)setObject:(id)obj forKeyedSubscript:(id)key;
107 - (id)objectForKeyedSubscript:(id)key;
110 @interface Test : Subscriptable
115 - (id)testUninitializedObject:(BOOL)keyed {
118 if (o[self]) // expected-warning {{Subscript access on an uninitialized object pointer [core.CallAndMessage]}}
119 return o; // no-warning (sink)
121 if (o[0]) // expected-warning {{Subscript access on an uninitialized object pointer [core.CallAndMessage]}}
122 return o; // no-warning (sink)
128 // TODO: If this hash ever changes, turn core.CallAndMessage:UndefReceiver from
129 // a checker option into a checker, as described in the CallAndMessage comments!
130 // CHECK: <key>issue_hash_content_of_line_in_context</key>
131 // CHECK-SAME: <string>8d943563d78377fc5dfcd4fdde904e5e</string>
132 // CHECK: <key>issue_hash_content_of_line_in_context</key>
133 // CHECK-SAME: <string>9a2a9698763d62bed38d91fe5fb4aefd</string>