1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -std=c++17 -verify %s
3 void clang_analyzer_eval(bool);
5 void array_value_a(void) {
10 int x
= a
; // expected-warning{{Assigned value is garbage or undefined}}
13 void array_value_b(void) {
17 clang_analyzer_eval(a
== 1); // expected-warning{{TRUE}}
18 clang_analyzer_eval(b
== 2); // expected-warning{{TRUE}}
20 int x
= a
; // no-warning
23 void array_value_c(void) {
30 clang_analyzer_eval(b
== arr
[1]); // expected-warning{{TRUE}}
32 int y
= b
; // no-warning
33 int x
= a
; // expected-warning{{Assigned value is garbage or undefined}}
36 void array_value_d(void) {
43 clang_analyzer_eval(b
== arr
[1]); // expected-warning{{TRUE}}
45 int y
= b
; // no-warning
46 int x
= c
; // expected-warning{{Assigned value is garbage or undefined}}
49 void array_value_e(void) {
57 clang_analyzer_eval(i
== 0); // expected-warning{{TRUE}}
58 clang_analyzer_eval(j
== 0); // expected-warning{{TRUE}}
60 int a
= i
; // no-warning
61 int b
= j
; // no-warning
64 void array_value_f(void) {
72 clang_analyzer_eval(i
== 0); // expected-warning{{TRUE}}
74 int a
= i
; // no-warning
75 int b
= j
; // expected-warning{{Assigned value is garbage or undefined}}
78 void array_lref_a(void) {
81 int x
= a
; // expected-warning{{Assigned value is garbage or undefined}}
84 void array_lref_b(void) {
88 clang_analyzer_eval(a
== 1); // expected-warning{{TRUE}}
89 clang_analyzer_eval(b
== 2); // expected-warning{{TRUE}}
91 int x
= a
; // no-warning
94 void array_lref_c(void) {
100 clang_analyzer_eval(a
== 1); // expected-warning{{TRUE}}
102 int x
= a
; // no-warning
103 int y
= b
; // expected-warning{{Assigned value is garbage or undefined}}
106 void array_lref_d(void) {
111 auto &[a
, b
, c
] = arr
;
113 clang_analyzer_eval(b
== 1); // expected-warning{{TRUE}}
115 int y
= b
; // no-warning
116 int x
= a
; // expected-warning{{Assigned value is garbage or undefined}}
119 void array_lref_e(void) {
124 auto &[a
, b
, c
] = arr
;
126 clang_analyzer_eval(b
== 1); // expected-warning{{TRUE}}
128 int y
= b
; // no-warning
129 int x
= c
; // expected-warning{{Assigned value is garbage or undefined}}
132 void array_lref_f(void) {
140 clang_analyzer_eval(i
== 0); // expected-warning{{TRUE}}
141 clang_analyzer_eval(j
== 0); // expected-warning{{TRUE}}
143 int a
= i
; // no-warning
144 int b
= j
; // no-warning
147 void array_lref_g(void) {
153 auto &[i
, j
] = uninit
;
155 clang_analyzer_eval(i
== 0); // expected-warning{{TRUE}}
157 int a
= i
; // no-warning
158 int b
= j
; // expected-warning{{Assigned value is garbage or undefined}}
161 void array_rref_a(void) {
164 int x
= a
; // expected-warning{{Assigned value is garbage or undefined}}
167 void array_rref_b(void) {
171 clang_analyzer_eval(a
== 1); // expected-warning{{TRUE}}
172 clang_analyzer_eval(b
== 2); // expected-warning{{TRUE}}
174 int x
= a
; // no-warning
177 void array_rref_c(void) {
183 clang_analyzer_eval(a
== 1); // expected-warning{{TRUE}}
185 int x
= a
; // no-warning
186 int y
= b
; // expected-warning{{Assigned value is garbage or undefined}}
189 void array_rref_d(void) {
194 auto &&[a
, b
, c
] = arr
;
196 clang_analyzer_eval(b
== 1); // expected-warning{{TRUE}}
198 int y
= b
; // no-warning
199 int x
= a
; // expected-warning{{Assigned value is garbage or undefined}}
202 void array_rref_e(void) {
207 auto &&[a
, b
, c
] = arr
;
209 clang_analyzer_eval(b
== 1); // expected-warning{{TRUE}}
211 int y
= b
; // no-warning
212 int x
= c
; // expected-warning{{Assigned value is garbage or undefined}}
215 void array_rref_f(void) {
221 auto &&[i
, j
] = init
;
223 clang_analyzer_eval(i
== 0); // expected-warning{{TRUE}}
224 clang_analyzer_eval(j
== 0); // expected-warning{{TRUE}}
226 int a
= i
; // no-warning
227 int b
= j
; // no-warning
230 void array_rref_g(void) {
236 auto &&[i
, j
] = uninit
;
238 clang_analyzer_eval(i
== 0); // expected-warning{{TRUE}}
240 int a
= i
; // no-warning
241 int b
= j
; // expected-warning{{Assigned value is garbage or undefined}}
244 void array_change_a(void) {
249 clang_analyzer_eval(a
== 1); // expected-warning{{TRUE}}
251 clang_analyzer_eval(a
== 3); // expected-warning{{TRUE}}
253 clang_analyzer_eval(arr
[0] == 1); // expected-warning{{TRUE}}
254 clang_analyzer_eval(arr
[1] == 2); // expected-warning{{TRUE}}
256 clang_analyzer_eval(b
== 2); // expected-warning{{TRUE}}
259 void array_change_b(void) {
264 clang_analyzer_eval(a
== 1); // expected-warning{{TRUE}}
265 clang_analyzer_eval(b
== 2); // expected-warning{{TRUE}}
268 clang_analyzer_eval(a
== 3); // expected-warning{{TRUE}}
270 clang_analyzer_eval(arr
[0] == 3); // expected-warning{{TRUE}}
271 clang_analyzer_eval(arr
[1] == 2); // expected-warning{{TRUE}}
274 void array_small_a(void) {
277 auto [a
, b
, c
, d
, e
] = arr
;
279 int x
= e
; // expected-warning{{Assigned value is garbage or undefined}}
282 void array_big_a(void) {
285 auto [a
, b
, c
, d
, e
, f
] = arr
;
287 // FIXME: These will be Undefined when we handle reading Undefined values from lazyCompoundVal.
288 clang_analyzer_eval(a
== 1); // expected-warning{{UNKNOWN}}
289 clang_analyzer_eval(b
== 2); // expected-warning{{UNKNOWN}}
290 clang_analyzer_eval(c
== 3); // expected-warning{{UNKNOWN}}
291 clang_analyzer_eval(d
== 4); // expected-warning{{UNKNOWN}}
292 clang_analyzer_eval(e
== 5); // expected-warning{{UNKNOWN}}
293 clang_analyzer_eval(f
== 6); // expected-warning{{UNKNOWN}}
301 void non_pod_val(void) {
306 clang_analyzer_eval(x
.a
== 1); // expected-warning{{TRUE}}
307 clang_analyzer_eval(x
.b
== 2); // expected-warning{{TRUE}}
309 clang_analyzer_eval(y
.a
== 1); // expected-warning{{TRUE}}
310 clang_analyzer_eval(y
.b
== 2); // expected-warning{{TRUE}}
313 void non_pod_val_syntax_2(void) {
318 clang_analyzer_eval(x
.a
== 1); // expected-warning{{TRUE}}
319 clang_analyzer_eval(x
.b
== 2); // expected-warning{{TRUE}}
321 clang_analyzer_eval(y
.a
== 1); // expected-warning{{TRUE}}
322 clang_analyzer_eval(y
.b
== 2); // expected-warning{{TRUE}}
325 void non_pod_lref(void) {
330 clang_analyzer_eval(x
.a
== 1); // expected-warning{{TRUE}}
331 clang_analyzer_eval(x
.b
== 2); // expected-warning{{TRUE}}
333 clang_analyzer_eval(y
.a
== 1); // expected-warning{{TRUE}}
334 clang_analyzer_eval(y
.b
== 2); // expected-warning{{TRUE}}
337 void non_pod_rref(void) {
342 clang_analyzer_eval(x
.a
== 1); // expected-warning{{TRUE}}
343 clang_analyzer_eval(x
.b
== 2); // expected-warning{{TRUE}}
345 clang_analyzer_eval(y
.a
== 1); // expected-warning{{TRUE}}
346 clang_analyzer_eval(y
.b
== 2); // expected-warning{{TRUE}}
350 inline static int c
= 0;
357 SUD(const SUD
©
) {
363 void non_pod_user_defined_val(void) {
368 clang_analyzer_eval(x
.a
== 2); // expected-warning{{TRUE}}
369 clang_analyzer_eval(x
.b
== 3); // expected-warning{{TRUE}}
371 clang_analyzer_eval(y
.a
== 2); // expected-warning{{TRUE}}
372 clang_analyzer_eval(y
.b
== 3); // expected-warning{{TRUE}}
375 void non_pod_user_defined_val_syntax_2(void) {
381 clang_analyzer_eval(SUD::c
== 2); // expected-warning{{TRUE}}
383 clang_analyzer_eval(x
.a
== 2); // expected-warning{{TRUE}}
384 clang_analyzer_eval(x
.b
== 3); // expected-warning{{TRUE}}
386 clang_analyzer_eval(y
.a
== 2); // expected-warning{{TRUE}}
387 clang_analyzer_eval(y
.b
== 3); // expected-warning{{TRUE}}