Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Analysis / uninit-structured-binding-struct.cpp
blobfec82c0d8589d6a9336d57a3bd7c759a75e08881
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -std=c++17 -verify %s
3 void clang_analyzer_eval(bool);
5 struct s {
6 int a;
7 int b;
8 };
10 void a(void) {
11 s tst;
13 auto [i, j] = tst;
15 int x = i; // expected-warning{{Assigned value is garbage or undefined}}
18 void b(void) {
19 s tst;
20 tst.a = 1;
22 auto [i, j] = tst;
24 clang_analyzer_eval(i == 1); // expected-warning{{TRUE}}
25 int y = j; // expected-warning{{Assigned value is garbage or undefined}}
28 void c(void) {
29 s tst;
31 auto &[i, j] = tst;
33 int x = i; // expected-warning{{Assigned value is garbage or undefined}}
36 void d(void) {
37 s tst;
38 tst.a = 1;
40 auto &[i, j] = tst;
42 clang_analyzer_eval(i == 1); // expected-warning{{TRUE}}
43 i = 2;
44 clang_analyzer_eval(tst.a == 2); // expected-warning{{TRUE}}
46 int y = j; // expected-warning{{Assigned value is garbage or undefined}}
49 void e(void) {
50 s tst;
51 tst.a = 1;
53 auto &[i, j] = tst;
55 clang_analyzer_eval(i == 1); // expected-warning{{TRUE}}
57 tst.b = 2;
58 clang_analyzer_eval(j == 2); // expected-warning{{TRUE}}
61 void f(void) {
62 s tst;
64 auto &&[i, j] = tst;
66 int x = i; // expected-warning{{Assigned value is garbage or undefined}}
69 void g(void) {
70 s tst;
71 tst.a = 1;
73 auto &&[i, j] = tst;
75 clang_analyzer_eval(i == 1); // expected-warning{{TRUE}}
76 int y = j; // expected-warning{{Assigned value is garbage or undefined}}
79 struct s2 {
80 int a = 1;
81 int b = 2;
84 struct s3 {
85 s x;
86 s2 y;
89 void h(void) {
90 s3 tst;
92 clang_analyzer_eval(tst.y.a == 1); // expected-warning{{TRUE}}
94 auto [i, j] = tst;
96 // FIXME: These should be undefined, but we have to fix
97 // reading undefined from lazy compound values first.
98 clang_analyzer_eval(i.a); // expected-warning{{UNKNOWN}}
99 clang_analyzer_eval(i.b); // expected-warning{{UNKNOWN}}
101 clang_analyzer_eval(j.a == 1); // expected-warning{{TRUE}}
102 clang_analyzer_eval(j.b == 2); // expected-warning{{TRUE}}
105 void i(void) {
106 s3 tst;
108 clang_analyzer_eval(tst.y.a == 1); // expected-warning{{TRUE}}
110 auto &[i, j] = tst;
111 j.a = 3;
113 clang_analyzer_eval(tst.y.a == 3); // expected-warning{{TRUE}}
114 clang_analyzer_eval(tst.y.b == 2); // expected-warning{{TRUE}}
115 clang_analyzer_eval(j.b == 2); // expected-warning{{TRUE}}