[RISCV][FMV] Support target_clones (#85786)
[llvm-project.git] / clang / test / Analysis / call-and-message.m
blob04dff2b5c2a55013195042c1e4bf2962098f2793
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;
28 @protocol NSObject
29 - (BOOL)isEqual:(id)object;
30 @end
31 @protocol NSCopying
32 - (id)copyWithZone:(NSZone *)zone;
33 @end
34 @protocol NSMutableCopying
35 - (id)mutableCopyWithZone:(NSZone *)zone;
36 @end
37 @protocol NSCoding
38 - (void)encodeWithCoder:(NSCoder *)aCoder;
39 @end
40 @interface NSObject <NSObject> {
42 @end
43 @class NSString, NSData;
44 @class NSString, NSData, NSMutableData, NSMutableDictionary, NSMutableArray;
45 typedef struct {
46 } NSFastEnumerationState;
47 @protocol NSFastEnumeration
48 - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len;
49 @end
50 @class NSData, NSIndexSet, NSString, NSURL;
51 @interface NSArray : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>
52 - (NSUInteger)count;
53 @end
54 @interface NSArray (NSArrayCreation)
55 + (id)array;
56 - (NSUInteger)length;
57 - (void)addObject:(id)object;
58 @end
59 extern NSString *const NSUndoManagerCheckpointNotification;
61 //===----------------------------------------------------------------------===//
62 // Test cases.
63 //===----------------------------------------------------------------------===//
65 unsigned f1(void) {
66   NSString *aString;
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;
78 @end
80 @implementation RDar9241180
81 @synthesize x;
82 - (id)testAnalyzer1:(int)y {
83   RDar9241180 *o;
84   if (y && o.x) // expected-warning {{Property access on an uninitialized object pointer [core.CallAndMessage]}}
85     return o;
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]}}
94 @end
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;
108 @end
110 @interface Test : Subscriptable
111 @end
113 @implementation Test
115 - (id)testUninitializedObject:(BOOL)keyed {
116   Test *o;
117   if (keyed) {
118     if (o[self]) // expected-warning {{Subscript access on an uninitialized object pointer [core.CallAndMessage]}}
119       return o;  // no-warning (sink)
120   } else {
121     if (o[0])   // expected-warning {{Subscript access on an uninitialized object pointer [core.CallAndMessage]}}
122       return o; // no-warning (sink)
123   }
124   return self;
126 @end
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>