File: uninit-structured-binding-array.cpp

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (388 lines) | stat: -rw-r--r-- 8,575 bytes parent folder | download | duplicates (10)
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -std=c++17 -verify %s

void clang_analyzer_eval(bool);

void array_value_a(void) {
  int arr[2];
  auto [a, b] = arr;
  arr[0] = 0;

  int x = a; // expected-warning{{Assigned value is garbage or undefined}}
}

void array_value_b(void) {
  int arr[] = {1, 2};
  auto [a, b] = arr;

  clang_analyzer_eval(a == 1); // expected-warning{{TRUE}}
  clang_analyzer_eval(b == 2); // expected-warning{{TRUE}}

  int x = a; // no-warning
}

void array_value_c(void) {
  int arr[3];

  arr[1] = 1;

  auto [a, b, c] = arr;

  clang_analyzer_eval(b == arr[1]); // expected-warning{{TRUE}}

  int y = b; // no-warning
  int x = a; // expected-warning{{Assigned value is garbage or undefined}}
}

void array_value_d(void) {
  int arr[3];

  arr[1] = 1;

  auto [a, b, c] = arr;

  clang_analyzer_eval(b == arr[1]); // expected-warning{{TRUE}}

  int y = b; // no-warning
  int x = c; // expected-warning{{Assigned value is garbage or undefined}}
}

void array_value_e(void) {
  int uninit[2];
  int init[2] = {0};

  uninit[0] = init[0];

  auto [i, j] = init;

  clang_analyzer_eval(i == 0); // expected-warning{{TRUE}}
  clang_analyzer_eval(j == 0); // expected-warning{{TRUE}}

  int a = i; // no-warning
  int b = j; // no-warning
}

void array_value_f(void) {
  int uninit[2];
  int init[2] = {0};

  uninit[0] = init[0];

  auto [i, j] = uninit;

  clang_analyzer_eval(i == 0); // expected-warning{{TRUE}}

  int a = i; // no-warning
  int b = j; // expected-warning{{Assigned value is garbage or undefined}}
}

void array_lref_a(void) {
  int arr[2];
  auto &[a, b] = arr;
  int x = a; // expected-warning{{Assigned value is garbage or undefined}}
}

void array_lref_b(void) {
  int arr[] = {1, 2};
  auto &[a, b] = arr;

  clang_analyzer_eval(a == 1); // expected-warning{{TRUE}}
  clang_analyzer_eval(b == 2); // expected-warning{{TRUE}}

  int x = a; // no-warning
}

void array_lref_c(void) {
  int arr[2];
  auto &[a, b] = arr;

  arr[0] = 1;

  clang_analyzer_eval(a == 1); // expected-warning{{TRUE}}

  int x = a; // no-warning
  int y = b; // expected-warning{{Assigned value is garbage or undefined}}
}

void array_lref_d(void) {
  int arr[3];

  arr[1] = 1;

  auto &[a, b, c] = arr;

  clang_analyzer_eval(b == 1); // expected-warning{{TRUE}}

  int y = b; // no-warning
  int x = a; // expected-warning{{Assigned value is garbage or undefined}}
}

void array_lref_e(void) {
  int arr[3];

  arr[1] = 1;

  auto &[a, b, c] = arr;

  clang_analyzer_eval(b == 1); // expected-warning{{TRUE}}

  int y = b; // no-warning
  int x = c; // expected-warning{{Assigned value is garbage or undefined}}
}

void array_lref_f(void) {
  int uninit[2];
  int init[2] = {0};

  uninit[0] = init[0];

  auto &[i, j] = init;

  clang_analyzer_eval(i == 0); // expected-warning{{TRUE}}
  clang_analyzer_eval(j == 0); // expected-warning{{TRUE}}

  int a = i; // no-warning
  int b = j; // no-warning
}

void array_lref_g(void) {
  int uninit[2];
  int init[2] = {0};

  uninit[0] = init[0];

  auto &[i, j] = uninit;

  clang_analyzer_eval(i == 0); // expected-warning{{TRUE}}

  int a = i; // no-warning
  int b = j; // expected-warning{{Assigned value is garbage or undefined}}
}

void array_rref_a(void) {
  int arr[2];
  auto &&[a, b] = arr;
  int x = a; // expected-warning{{Assigned value is garbage or undefined}}
}

void array_rref_b(void) {
  int arr[] = {1, 2};
  auto &&[a, b] = arr;

  clang_analyzer_eval(a == 1); // expected-warning{{TRUE}}
  clang_analyzer_eval(b == 2); // expected-warning{{TRUE}}

  int x = a; // no-warning
}

void array_rref_c(void) {
  int arr[2];
  auto &&[a, b] = arr;

  arr[0] = 1;

  clang_analyzer_eval(a == 1); // expected-warning{{TRUE}}

  int x = a; // no-warning
  int y = b; // expected-warning{{Assigned value is garbage or undefined}}
}

void array_rref_d(void) {
  int arr[3];

  arr[1] = 1;

  auto &&[a, b, c] = arr;

  clang_analyzer_eval(b == 1); // expected-warning{{TRUE}}

  int y = b; // no-warning
  int x = a; // expected-warning{{Assigned value is garbage or undefined}}
}

void array_rref_e(void) {
  int arr[3];

  arr[1] = 1;

  auto &&[a, b, c] = arr;

  clang_analyzer_eval(b == 1); // expected-warning{{TRUE}}

  int y = b; // no-warning
  int x = c; // expected-warning{{Assigned value is garbage or undefined}}
}

void array_rref_f(void) {
  int uninit[2];
  int init[2] = {0};

  uninit[0] = init[0];

  auto &&[i, j] = init;

  clang_analyzer_eval(i == 0); // expected-warning{{TRUE}}
  clang_analyzer_eval(j == 0); // expected-warning{{TRUE}}

  int a = i; // no-warning
  int b = j; // no-warning
}

void array_rref_g(void) {
  int uninit[2];
  int init[2] = {0};

  uninit[0] = init[0];

  auto &&[i, j] = uninit;

  clang_analyzer_eval(i == 0); // expected-warning{{TRUE}}

  int a = i; // no-warning
  int b = j; // expected-warning{{Assigned value is garbage or undefined}}
}

void array_change_a(void) {
  int arr[] = {1, 2};

  auto [a, b] = arr;

  clang_analyzer_eval(a == 1); // expected-warning{{TRUE}}
  a = 3;
  clang_analyzer_eval(a == 3); // expected-warning{{TRUE}}

  clang_analyzer_eval(arr[0] == 1); // expected-warning{{TRUE}}
  clang_analyzer_eval(arr[1] == 2); // expected-warning{{TRUE}}

  clang_analyzer_eval(b == 2); // expected-warning{{TRUE}}
}

void array_change_b(void) {
  int arr[] = {1, 2};

  auto &[a, b] = arr;

  clang_analyzer_eval(a == 1); // expected-warning{{TRUE}}
  clang_analyzer_eval(b == 2); // expected-warning{{TRUE}}

  a = 3;
  clang_analyzer_eval(a == 3); // expected-warning{{TRUE}}

  clang_analyzer_eval(arr[0] == 3); // expected-warning{{TRUE}}
  clang_analyzer_eval(arr[1] == 2); // expected-warning{{TRUE}}
}

void array_small_a(void) {
  int arr[5];

  auto [a, b, c, d, e] = arr;

  int x = e; // expected-warning{{Assigned value is garbage or undefined}}
}

void array_big_a(void) {
  int arr[6];

  auto [a, b, c, d, e, f] = arr;

  // FIXME: These will be Undefined when we handle reading Undefined values from lazyCompoundVal.
  clang_analyzer_eval(a == 1); // expected-warning{{UNKNOWN}}
  clang_analyzer_eval(b == 2); // expected-warning{{UNKNOWN}}
  clang_analyzer_eval(c == 3); // expected-warning{{UNKNOWN}}
  clang_analyzer_eval(d == 4); // expected-warning{{UNKNOWN}}
  clang_analyzer_eval(e == 5); // expected-warning{{UNKNOWN}}
  clang_analyzer_eval(f == 6); // expected-warning{{UNKNOWN}}
}

struct S {
  int a = 1;
  int b = 2;
};

void non_pod_val(void) {
  S arr[2];

  auto [x, y] = arr;

  clang_analyzer_eval(x.a == 1); // expected-warning{{TRUE}}
  clang_analyzer_eval(x.b == 2); // expected-warning{{TRUE}}

  clang_analyzer_eval(y.a == 1); // expected-warning{{TRUE}}
  clang_analyzer_eval(y.b == 2); // expected-warning{{TRUE}}
}

void non_pod_val_syntax_2(void) {
  S arr[2];

  auto [x, y](arr);

  clang_analyzer_eval(x.a == 1); // expected-warning{{TRUE}}
  clang_analyzer_eval(x.b == 2); // expected-warning{{TRUE}}

  clang_analyzer_eval(y.a == 1); // expected-warning{{TRUE}}
  clang_analyzer_eval(y.b == 2); // expected-warning{{TRUE}}
}

void non_pod_lref(void) {
  S arr[2];

  auto &[x, y] = arr;

  clang_analyzer_eval(x.a == 1); // expected-warning{{TRUE}}
  clang_analyzer_eval(x.b == 2); // expected-warning{{TRUE}}

  clang_analyzer_eval(y.a == 1); // expected-warning{{TRUE}}
  clang_analyzer_eval(y.b == 2); // expected-warning{{TRUE}}
}

void non_pod_rref(void) {
  S arr[2];

  auto &&[x, y] = arr;

  clang_analyzer_eval(x.a == 1); // expected-warning{{TRUE}}
  clang_analyzer_eval(x.b == 2); // expected-warning{{TRUE}}

  clang_analyzer_eval(y.a == 1); // expected-warning{{TRUE}}
  clang_analyzer_eval(y.b == 2); // expected-warning{{TRUE}}
}

struct SUD {
  inline static int c = 0;

  int a = 1;
  int b = 2;

  SUD() { ++c; };

  SUD(const SUD &copy) {
    a = copy.a + 1;
    b = copy.b + 1;
  }
};

void non_pod_user_defined_val(void) {
  SUD arr[2];

  auto [x, y] = arr;

  clang_analyzer_eval(x.a == 2); // expected-warning{{TRUE}}
  clang_analyzer_eval(x.b == 3); // expected-warning{{TRUE}}

  clang_analyzer_eval(y.a == 2); // expected-warning{{TRUE}}
  clang_analyzer_eval(y.b == 3); // expected-warning{{TRUE}}
}

void non_pod_user_defined_val_syntax_2(void) {
  SUD::c = 0;
  SUD arr[2];

  auto [x, y](arr);

  clang_analyzer_eval(SUD::c == 2); // expected-warning{{TRUE}}

  clang_analyzer_eval(x.a == 2); // expected-warning{{TRUE}}
  clang_analyzer_eval(x.b == 3); // expected-warning{{TRUE}}

  clang_analyzer_eval(y.a == 2); // expected-warning{{TRUE}}
  clang_analyzer_eval(y.b == 3); // expected-warning{{TRUE}}
}