1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-disable-checker=cplusplus -analyzer-config c++-inlining=constructors -verify %s
3 #include "Inputs/system-header-simulator-cxx.h"
5 void clang_analyzer_eval(bool);
15 // expected-warning@-1{{Assigned value is garbage or undefined}}
21 // expected-warning@-1{{Assigned value is garbage or undefined}}
27 // expected-warning@-1{{Assigned value is garbage or undefined}}
38 clang_analyzer_eval(arr
[0].y
== 2); // expected-warning{{TRUE}}
40 // expected-warning@-1{{Assigned value is garbage or undefined}}
46 clang_analyzer_eval(arr
[1].y
== 2); // expected-warning{{TRUE}}
48 // expected-warning@-1{{Assigned value is garbage or undefined}}
54 clang_analyzer_eval(arr
[2].y
== 2); // expected-warning{{TRUE}}
56 // expected-warning@-1{{Assigned value is garbage or undefined}}
64 clang_analyzer_eval(arr
[1].y
== 2); // expected-warning{{TRUE}}
65 clang_analyzer_eval(arr
[1].x
== 3); // expected-warning{{TRUE}}
71 clang_analyzer_eval(arr
[1].y
== 2); // expected-warning{{TRUE}}
73 // expected-warning@-1{{Assigned value is garbage or undefined}}
90 clang_analyzer_eval(arr
[0].arr
[0].x
== 1); // expected-warning{{TRUE}}
91 clang_analyzer_eval(arr
[0].arr
[0].y
== 2); // expected-warning{{TRUE}}
93 clang_analyzer_eval(arr
[0].arr
[1].x
== 1); // expected-warning{{TRUE}}
94 clang_analyzer_eval(arr
[0].arr
[1].y
== 2); // expected-warning{{TRUE}}
96 clang_analyzer_eval(arr
[1].arr
[0].x
== 1); // expected-warning{{TRUE}}
97 clang_analyzer_eval(arr
[1].arr
[0].y
== 2); // expected-warning{{TRUE}}
99 clang_analyzer_eval(arr
[1].arr
[1].x
== 1); // expected-warning{{TRUE}}
100 clang_analyzer_eval(arr
[1].arr
[1].y
== 2); // expected-warning{{TRUE}}
102 int x
= arr
[1].sarr
[1].x
;
103 // expected-warning@-1{{Assigned value is garbage or undefined}}
109 clang_analyzer_eval(arr
[1][1].y
== 2); // expected-warning{{TRUE}}
111 // expected-warning@-1{{Assigned value is garbage or undefined}}
122 // FIXME: This test requires -analyzer-disable-checker=cplusplus,
123 // because of the checker's weird behaviour in case of arrays.
125 // s3 *arr = new s3[4];
126 // s3 *arr2 = new (arr + 1) s3[1];
127 // ^~~~~~~~~~~~~~~~~~~
128 // warning: 12 bytes is possibly not enough
129 // for array allocation which requires
136 clang_analyzer_eval(arr
[0].x
== 0); // expected-warning{{TRUE}}
137 clang_analyzer_eval(arr
[1].x
== 4); // expected-warning{{TRUE}}
138 clang_analyzer_eval(arr
[2].x
== 5); // expected-warning{{TRUE}}
139 clang_analyzer_eval(arr
[3].x
== 6); // expected-warning{{TRUE}}
146 clang_analyzer_eval(arr
[0].x
== 0); // expected-warning{{TRUE}}
147 clang_analyzer_eval(arr
[1].x
== 1); // expected-warning{{TRUE}}
148 clang_analyzer_eval(arr
[2].x
== 2); // expected-warning{{TRUE}}
149 clang_analyzer_eval(arr
[3].x
== 3); // expected-warning{{TRUE}}
156 clang_analyzer_eval(arr
[0][0].x
== 0); // expected-warning{{TRUE}}
157 clang_analyzer_eval(arr
[0][1].x
== 1); // expected-warning{{TRUE}}
158 clang_analyzer_eval(arr
[1][0].x
== 2); // expected-warning{{TRUE}}
159 clang_analyzer_eval(arr
[1][1].x
== 3); // expected-warning{{TRUE}}
166 clang_analyzer_eval(a
[0][0].x
== 0); // expected-warning{{TRUE}}
167 clang_analyzer_eval(a
[0][1].x
== 1); // expected-warning{{TRUE}}
168 clang_analyzer_eval(a
[1][0].x
== 2); // expected-warning{{TRUE}}
169 clang_analyzer_eval(a
[1][1].x
== 3); // expected-warning{{TRUE}}
171 clang_analyzer_eval(b
[0][0].x
== 4); // expected-warning{{TRUE}}
172 clang_analyzer_eval(b
[0][1].x
== 5); // expected-warning{{TRUE}}
173 clang_analyzer_eval(b
[1][0].x
== 6); // expected-warning{{TRUE}}
174 clang_analyzer_eval(b
[1][1].x
== 7); // expected-warning{{TRUE}}
181 // expected-warning@-1{{Assigned value is garbage or undefined}}
188 // expected-warning@-1{{Assigned value is garbage or undefined}}
195 Base(int x
, int y
) : x(x
), y(y
) {}
198 struct Derived
: public Base
{
202 Derived(int x
, int y
, int i
, int j
) : Base(x
, y
), i(i
), j(j
) {}
205 void delegate(void) {
206 Derived arr
[2] = {{1, 2, 3, 4}, {5, 6, 7, 8}};
208 clang_analyzer_eval(arr
[0].x
== 1); // expected-warning{{TRUE}}
209 clang_analyzer_eval(arr
[0].y
== 2); // expected-warning{{TRUE}}
210 clang_analyzer_eval(arr
[0].i
== 3); // expected-warning{{TRUE}}
211 clang_analyzer_eval(arr
[0].j
== 4); // expected-warning{{TRUE}}
213 clang_analyzer_eval(arr
[1].x
== 5); // expected-warning{{TRUE}}
214 clang_analyzer_eval(arr
[1].y
== 6); // expected-warning{{TRUE}}
215 clang_analyzer_eval(arr
[1].i
== 7); // expected-warning{{TRUE}}
216 clang_analyzer_eval(arr
[1].j
== 8); // expected-warning{{TRUE}}
219 void delegate_heap(void) {
220 Derived
*arr
= new Derived
[2]{{1, 2, 3, 4}, {5, 6, 7, 8}};
222 clang_analyzer_eval(arr
[0].x
== 1); // expected-warning{{TRUE}}
223 clang_analyzer_eval(arr
[0].y
== 2); // expected-warning{{TRUE}}
224 clang_analyzer_eval(arr
[0].i
== 3); // expected-warning{{TRUE}}
225 clang_analyzer_eval(arr
[0].j
== 4); // expected-warning{{TRUE}}
227 clang_analyzer_eval(arr
[1].x
== 5); // expected-warning{{TRUE}}
228 clang_analyzer_eval(arr
[1].y
== 6); // expected-warning{{TRUE}}
229 clang_analyzer_eval(arr
[1].i
== 7); // expected-warning{{TRUE}}
230 clang_analyzer_eval(arr
[1].j
== 8); // expected-warning{{TRUE}}
241 Parent() : arr
{{1, 2}, {3, 4}} {}
247 // FIXME: Ideally these are TRUE, but at the moment InitListExpr has no
248 // knowledge about where the initializer list is used, so we can't bind
249 // the initializer list to the required region.
250 clang_analyzer_eval(arr
[0].arr
[0].x
== 1); // expected-warning{{UNKNOWN}}
251 clang_analyzer_eval(arr
[0].arr
[0].y
== 2); // expected-warning{{UNKNOWN}}
252 clang_analyzer_eval(arr
[0].arr
[1].x
== 3); // expected-warning{{UNKNOWN}}
253 clang_analyzer_eval(arr
[0].arr
[1].y
== 4); // expected-warning{{UNKNOWN}}
255 clang_analyzer_eval(arr
[1].arr
[0].x
== 1); // expected-warning{{UNKNOWN}}
256 clang_analyzer_eval(arr
[1].arr
[0].y
== 2); // expected-warning{{UNKNOWN}}
257 clang_analyzer_eval(arr
[1].arr
[1].x
== 3); // expected-warning{{UNKNOWN}}
258 clang_analyzer_eval(arr
[1].arr
[1].y
== 4); // expected-warning{{UNKNOWN}}