call-and-message.cpp
7.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// RUN: %clang_analyze_cc1 %s -verify=fn-pointer \
// RUN: -analyzer-checker=core \
// RUN: -analyzer-config core.CallAndMessage:FunctionPointer=true \
// RUN: -analyzer-config core.CallAndMessage:ParameterCount=false \
// RUN: -analyzer-config core.CallAndMessage:CXXThisMethodCall=false \
// RUN: -analyzer-config core.CallAndMessage:CXXDeallocationArg=false \
// RUN: -analyzer-config core.CallAndMessage:ArgInitializedness=false \
// RUN: -analyzer-config core.CallAndMessage:ArgPointeeInitializedness=false \
// RUN: -analyzer-config core.CallAndMessage:NilReceiver=false \
// RUN: -analyzer-config core.CallAndMessage:UndefReceiver=false
// RUN: %clang_analyze_cc1 %s -verify=param-count \
// RUN: -analyzer-checker=core \
// RUN: -analyzer-config core.CallAndMessage:FunctionPointer=false \
// RUN: -analyzer-config core.CallAndMessage:ParameterCount=true \
// RUN: -analyzer-config core.CallAndMessage:CXXThisMethodCall=false \
// RUN: -analyzer-config core.CallAndMessage:CXXDeallocationArg=false \
// RUN: -analyzer-config core.CallAndMessage:ArgInitializedness=false \
// RUN: -analyzer-config core.CallAndMessage:ArgPointeeInitializedness=false \
// RUN: -analyzer-config core.CallAndMessage:NilReceiver=false \
// RUN: -analyzer-config core.CallAndMessage:UndefReceiver=false
// RUN: %clang_analyze_cc1 %s -verify=method \
// RUN: -analyzer-checker=core \
// RUN: -analyzer-config core.CallAndMessage:FunctionPointer=false \
// RUN: -analyzer-config core.CallAndMessage:ParameterCount=false \
// RUN: -analyzer-config core.CallAndMessage:CXXThisMethodCall=true \
// RUN: -analyzer-config core.CallAndMessage:CXXDeallocationArg=false \
// RUN: -analyzer-config core.CallAndMessage:ArgInitializedness=false \
// RUN: -analyzer-config core.CallAndMessage:ArgPointeeInitializedness=false \
// RUN: -analyzer-config core.CallAndMessage:NilReceiver=false \
// RUN: -analyzer-config core.CallAndMessage:UndefReceiver=false
// RUN: %clang_analyze_cc1 %s -verify=delete \
// RUN: -analyzer-checker=core \
// RUN: -analyzer-config core.CallAndMessage:FunctionPointer=false \
// RUN: -analyzer-config core.CallAndMessage:ParameterCount=false \
// RUN: -analyzer-config core.CallAndMessage:CXXThisMethodCall=false \
// RUN: -analyzer-config core.CallAndMessage:CXXDeallocationArg=true \
// RUN: -analyzer-config core.CallAndMessage:ArgInitializedness=false \
// RUN: -analyzer-config core.CallAndMessage:ArgPointeeInitializedness=false \
// RUN: -analyzer-config core.CallAndMessage:NilReceiver=false \
// RUN: -analyzer-config core.CallAndMessage:UndefReceiver=false
// RUN: %clang_analyze_cc1 %s -verify=arg-init \
// RUN: -analyzer-checker=core \
// RUN: -analyzer-config core.CallAndMessage:FunctionPointer=false \
// RUN: -analyzer-config core.CallAndMessage:ParameterCount=false \
// RUN: -analyzer-config core.CallAndMessage:CXXThisMethodCall=false \
// RUN: -analyzer-config core.CallAndMessage:CXXDeallocationArg=false \
// RUN: -analyzer-config core.CallAndMessage:ArgInitializedness=true \
// RUN: -analyzer-config core.CallAndMessage:ArgPointeeInitializedness=false \
// RUN: -analyzer-config core.CallAndMessage:NilReceiver=false \
// RUN: -analyzer-config core.CallAndMessage:UndefReceiver=false
// Testing for ArgPointeeInitializedness is in call-and-message.c.
// RUN: %clang_analyze_cc1 %s \
// RUN: -verify=fn-pointer,param-count,method,delete,arg-init \
// RUN: -analyzer-checker=core \
// RUN: -analyzer-output=plist -o %t.plist
// RUN: cat %t.plist | FileCheck %s
namespace function_pointer {
using Fn = void (*)();
void uninit() {
Fn f;
f(); // fn-pointer-warning{{Called function pointer is an uninitialized pointer value [core.CallAndMessage]}}
}
void null() {
Fn f = nullptr;
f(); // fn-pointer-warning{{Called function pointer is null (null dereference) [core.CallAndMessage]}}
}
// TODO: If this hash ever changes, turn
// core.CallAndMessage:FunctionPointer from a checker option into a
// checker, as described in the CallAndMessage comments!
// CHECK: <key>issue_hash_content_of_line_in_context</key>
// CHECK-SAME: <string>eb2083c01775eef452afa75728dd4d8f</string>
// CHECK: <key>issue_hash_content_of_line_in_context</key>
// CHECK-SAME: <string>407c50d9bedd8db28bf34f9411308100</string>
} // namespace function_pointer
namespace wrong_param_count {
using FnOneParam = void (*)(int);
using FnTwoParam = void (*)(int, int);
void f(int, int) {}
void wrong_cast() {
FnTwoParam f1 = f;
FnOneParam f2 = reinterpret_cast<FnOneParam>(f1);
f2(5); // param-count-warning{{Function taking 2 arguments is called with fewer (1) [core.CallAndMessage]}}
}
// TODO: If this hash ever changes, turn
// core.CallAndMessage:ParameterCount from a checker option into a
// checker, as described in the CallAndMessage comments!
// CHECK: <key>issue_hash_content_of_line_in_context</key>
// CHECK-SAME: <string>9ff0e9b728422017945c9d5a673de223</string>
} // namespace wrong_param_count
namespace method_call {
struct A {
void m();
};
void uninit() {
A *a;
a->m(); // method-warning{{Called C++ object pointer is uninitialized [core.CallAndMessage]}}
}
// TODO: If this hash ever changes, turn
// core.CallAndMessage:CXXThisMethodCall from a checker option into a
// checker, as described in the CallAndMessage comments!
// CHECK: <key>issue_hash_content_of_line_in_context</key>
// CHECK-SAME: <string>7bc35c70465837948a3f5018f27b21cd</string>
void null() {
A *a = nullptr;
a->m(); // method-warning{{Called C++ object pointer is null [core.CallAndMessage]}}
}
// TODO: If this hash ever changes, turn
// core.CallAndMessage:CXXThisMethodCall from a checker option into a
// checker, as described in the CallAndMessage comments!
// CHECK: <key>issue_hash_content_of_line_in_context</key>
// CHECK-SAME: <string>8ec260c9ef11d7c51fa872212df1163f</string>
} // namespace method_call
namespace operator_delete {
void f() {
int *i;
delete i; // delete-warning{{Argument to 'delete' is uninitialized [core.CallAndMessage]}}
}
// TODO: If this hash ever changes, turn
// core.CallAndMessage:CXXDeallocationArg from a checker option into a
// checker, as described in the CallAndMessage comments!
// CHECK: <key>issue_hash_content_of_line_in_context</key>
// CHECK-SAME: <string>a8ff99ebaa8746457d3e14af8ef7e75c</string>
} // namespace operator_delete
namespace uninit_arg {
template <class T>
void consume(T);
void fundamental_uninit() {
int i;
consume(i); // arg-init-warning{{1st function call argument is an uninitialized value [core.CallAndMessage]}}
}
struct A {
int i;
};
void record_uninit() {
A a;
consume(a); // arg-init-warning{{Passed-by-value struct argument contains uninitialized data (e.g., field: 'i') [core.CallAndMessage]}}
}
// TODO: If this hash ever changes, turn
// core.CallAndMessage:ArgInitializedness from a checker option into a
// checker, as described in the CallAndMessage comments!
// CHECK: <key>issue_hash_content_of_line_in_context</key>
// CHECK-SAME: <string>a46bb5c1ee44d4611ffeb13f7f499605</string>
// CHECK: <key>issue_hash_content_of_line_in_context</key>
// CHECK-SAME: <string>e0e0d30ea5a7b2e3a71e1931fa0768a5</string>
} // namespace uninit_arg