Ted Kremenek | 0a65f94 | 2011-03-17 03:06:07 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -Wuninitialized -Wconditional-uninitialized -fsyntax-only -fblocks %s -verify |
Ted Kremenek | 610068c | 2011-01-15 02:58:47 +0000 | [diff] [blame] | 2 | |
| 3 | int test1() { |
Ted Kremenek | 609e317 | 2011-02-02 23:35:53 +0000 | [diff] [blame] | 4 | int x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} |
Chandler Carruth | f04eb2d | 2011-04-08 06:33:38 +0000 | [diff] [blame] | 5 | return x; // expected-warning{{variable 'x' is uninitialized when used here}} |
Ted Kremenek | 610068c | 2011-01-15 02:58:47 +0000 | [diff] [blame] | 6 | } |
| 7 | |
| 8 | int test2() { |
| 9 | int x = 0; |
| 10 | return x; // no-warning |
| 11 | } |
| 12 | |
| 13 | int test3() { |
| 14 | int x; |
| 15 | x = 0; |
| 16 | return x; // no-warning |
| 17 | } |
| 18 | |
| 19 | int test4() { |
Ted Kremenek | 609e317 | 2011-02-02 23:35:53 +0000 | [diff] [blame] | 20 | int x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} |
Chandler Carruth | f04eb2d | 2011-04-08 06:33:38 +0000 | [diff] [blame] | 21 | ++x; // expected-warning{{variable 'x' is uninitialized when used here}} |
Ted Kremenek | 610068c | 2011-01-15 02:58:47 +0000 | [diff] [blame] | 22 | return x; |
| 23 | } |
| 24 | |
| 25 | int test5() { |
Ted Kremenek | 609e317 | 2011-02-02 23:35:53 +0000 | [diff] [blame] | 26 | int x, y; // expected-note{{variable 'y' is declared here}} expected-note{{add initialization to silence this warning}} |
Chandler Carruth | f04eb2d | 2011-04-08 06:33:38 +0000 | [diff] [blame] | 27 | x = y; // expected-warning{{variable 'y' is uninitialized when used here}} |
Ted Kremenek | 610068c | 2011-01-15 02:58:47 +0000 | [diff] [blame] | 28 | return x; |
| 29 | } |
| 30 | |
| 31 | int test6() { |
Ted Kremenek | 609e317 | 2011-02-02 23:35:53 +0000 | [diff] [blame] | 32 | int x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} |
Chandler Carruth | f04eb2d | 2011-04-08 06:33:38 +0000 | [diff] [blame] | 33 | x += 2; // expected-warning{{variable 'x' is uninitialized when used here}} |
Ted Kremenek | 610068c | 2011-01-15 02:58:47 +0000 | [diff] [blame] | 34 | return x; |
| 35 | } |
| 36 | |
| 37 | int test7(int y) { |
Ted Kremenek | 609e317 | 2011-02-02 23:35:53 +0000 | [diff] [blame] | 38 | int x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} |
Ted Kremenek | 610068c | 2011-01-15 02:58:47 +0000 | [diff] [blame] | 39 | if (y) |
| 40 | x = 1; |
Chandler Carruth | 584b9d6 | 2011-04-08 06:47:15 +0000 | [diff] [blame] | 41 | return x; // expected-warning{{variable 'x' may be uninitialized when used here}} |
Ted Kremenek | 610068c | 2011-01-15 02:58:47 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | int test8(int y) { |
| 45 | int x; |
| 46 | if (y) |
| 47 | x = 1; |
| 48 | else |
| 49 | x = 0; |
Ted Kremenek | 609e317 | 2011-02-02 23:35:53 +0000 | [diff] [blame] | 50 | return x; |
Ted Kremenek | 610068c | 2011-01-15 02:58:47 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | int test9(int n) { |
Ted Kremenek | 609e317 | 2011-02-02 23:35:53 +0000 | [diff] [blame] | 54 | int x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} |
Ted Kremenek | 610068c | 2011-01-15 02:58:47 +0000 | [diff] [blame] | 55 | for (unsigned i = 0 ; i < n; ++i) { |
| 56 | if (i == n - 1) |
| 57 | break; |
Ted Kremenek | 94b1b4d | 2011-01-21 19:41:41 +0000 | [diff] [blame] | 58 | x = 1; |
Ted Kremenek | 610068c | 2011-01-15 02:58:47 +0000 | [diff] [blame] | 59 | } |
Chandler Carruth | 584b9d6 | 2011-04-08 06:47:15 +0000 | [diff] [blame] | 60 | return x; // expected-warning{{variable 'x' may be uninitialized when used here}} |
Ted Kremenek | 610068c | 2011-01-15 02:58:47 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | int test10(unsigned n) { |
Ted Kremenek | 609e317 | 2011-02-02 23:35:53 +0000 | [diff] [blame] | 64 | int x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} |
Ted Kremenek | 610068c | 2011-01-15 02:58:47 +0000 | [diff] [blame] | 65 | for (unsigned i = 0 ; i < n; ++i) { |
| 66 | x = 1; |
| 67 | } |
Chandler Carruth | 584b9d6 | 2011-04-08 06:47:15 +0000 | [diff] [blame] | 68 | return x; // expected-warning{{variable 'x' may be uninitialized when used here}} |
Ted Kremenek | 610068c | 2011-01-15 02:58:47 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | int test11(unsigned n) { |
Ted Kremenek | 609e317 | 2011-02-02 23:35:53 +0000 | [diff] [blame] | 72 | int x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} |
Ted Kremenek | 610068c | 2011-01-15 02:58:47 +0000 | [diff] [blame] | 73 | for (unsigned i = 0 ; i <= n; ++i) { |
| 74 | x = 1; |
| 75 | } |
Chandler Carruth | 584b9d6 | 2011-04-08 06:47:15 +0000 | [diff] [blame] | 76 | return x; // expected-warning{{variable 'x' may be uninitialized when used here}} |
Ted Kremenek | 610068c | 2011-01-15 02:58:47 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | void test12(unsigned n) { |
Chandler Carruth | 584b9d6 | 2011-04-08 06:47:15 +0000 | [diff] [blame] | 80 | for (unsigned i ; n ; ++i) ; // expected-warning{{variable 'i' may be uninitialized when used here}} expected-note{{variable 'i' is declared here}} expected-note{{add initialization to silence this warning}} |
Ted Kremenek | 610068c | 2011-01-15 02:58:47 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | int test13() { |
| 84 | static int i; |
| 85 | return i; // no-warning |
| 86 | } |
| 87 | |
Ted Kremenek | c104e53 | 2011-01-18 04:53:25 +0000 | [diff] [blame] | 88 | // Simply don't crash on this test case. |
| 89 | void test14() { |
| 90 | const char *p = 0; |
| 91 | for (;;) {} |
| 92 | } |
Ted Kremenek | 610068c | 2011-01-15 02:58:47 +0000 | [diff] [blame] | 93 | |
Chandler Carruth | b88fb02 | 2011-04-05 21:36:30 +0000 | [diff] [blame] | 94 | int test15() { |
| 95 | int x = x; // no-warning: signals intended lack of initialization. \ |
| 96 | // expected-note{{variable 'x' is declared here}} |
Chandler Carruth | f04eb2d | 2011-04-08 06:33:38 +0000 | [diff] [blame] | 97 | return x; // expected-warning{{variable 'x' is uninitialized when used here}} |
Ted Kremenek | c104e53 | 2011-01-18 04:53:25 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | // Don't warn in the following example; shows dataflow confluence. |
| 101 | char *test16_aux(); |
| 102 | void test16() { |
| 103 | char *p = test16_aux(); |
| 104 | for (unsigned i = 0 ; i < 100 ; i++) |
| 105 | p[i] = 'a'; // no-warning |
| 106 | } |
Ted Kremenek | c21fed3 | 2011-01-18 21:18:58 +0000 | [diff] [blame] | 107 | |
| 108 | void test17() { |
| 109 | // Don't warn multiple times about the same uninitialized variable |
| 110 | // along the same path. |
Ted Kremenek | 609e317 | 2011-02-02 23:35:53 +0000 | [diff] [blame] | 111 | int *x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} |
Chandler Carruth | f04eb2d | 2011-04-08 06:33:38 +0000 | [diff] [blame] | 112 | *x = 1; // expected-warning{{variable 'x' is uninitialized when used here}} |
Ted Kremenek | c21fed3 | 2011-01-18 21:18:58 +0000 | [diff] [blame] | 113 | *x = 1; // no-warning |
| 114 | } |
Ted Kremenek | 13bd423 | 2011-01-20 17:37:17 +0000 | [diff] [blame] | 115 | |
| 116 | int test18(int x, int y) { |
| 117 | int z; |
| 118 | if (x && y && (z = 1)) { |
| 119 | return z; // no-warning |
| 120 | } |
| 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | int test19_aux1(); |
| 125 | int test19_aux2(); |
| 126 | int test19_aux3(int *x); |
| 127 | int test19() { |
| 128 | int z; |
| 129 | if (test19_aux1() + test19_aux2() && test19_aux1() && test19_aux3(&z)) |
| 130 | return z; // no-warning |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | int test20() { |
Ted Kremenek | 609e317 | 2011-02-02 23:35:53 +0000 | [diff] [blame] | 135 | int z; // expected-note{{variable 'z' is declared here}} expected-note{{add initialization to silence this warning}} |
Ted Kremenek | 13bd423 | 2011-01-20 17:37:17 +0000 | [diff] [blame] | 136 | if ((test19_aux1() + test19_aux2() && test19_aux1()) || test19_aux3(&z)) |
Chandler Carruth | 584b9d6 | 2011-04-08 06:47:15 +0000 | [diff] [blame] | 137 | return z; // expected-warning{{variable 'z' may be uninitialized when used here}} |
Ted Kremenek | 13bd423 | 2011-01-20 17:37:17 +0000 | [diff] [blame] | 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | int test21(int x, int y) { |
Ted Kremenek | 609e317 | 2011-02-02 23:35:53 +0000 | [diff] [blame] | 142 | int z; // expected-note{{variable 'z' is declared here}} expected-note{{add initialization to silence this warning}} |
Ted Kremenek | 13bd423 | 2011-01-20 17:37:17 +0000 | [diff] [blame] | 143 | if ((x && y) || test19_aux3(&z) || test19_aux2()) |
Chandler Carruth | 584b9d6 | 2011-04-08 06:47:15 +0000 | [diff] [blame] | 144 | return z; // expected-warning{{variable 'z' may be uninitialized when used here}} |
Ted Kremenek | 13bd423 | 2011-01-20 17:37:17 +0000 | [diff] [blame] | 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | int test22() { |
| 149 | int z; |
| 150 | while (test19_aux1() + test19_aux2() && test19_aux1() && test19_aux3(&z)) |
| 151 | return z; // no-warning |
| 152 | return 0; |
| 153 | } |
| 154 | |
| 155 | int test23() { |
| 156 | int z; |
| 157 | for ( ; test19_aux1() + test19_aux2() && test19_aux1() && test19_aux3(&z) ; ) |
| 158 | return z; // no-warning |
| 159 | return 0; |
| 160 | } |
| 161 | |
| 162 | // The basic uninitialized value analysis doesn't have enough path-sensitivity |
| 163 | // to catch initializations relying on control-dependencies spanning multiple |
| 164 | // conditionals. This possibly can be handled by making the CFG itself |
| 165 | // represent such control-dependencies, but it is a niche case. |
| 166 | int test24(int flag) { |
Ted Kremenek | 609e317 | 2011-02-02 23:35:53 +0000 | [diff] [blame] | 167 | unsigned val; // expected-note{{variable 'val' is declared here}} expected-note{{add initialization to silence this warning}} |
Ted Kremenek | 13bd423 | 2011-01-20 17:37:17 +0000 | [diff] [blame] | 168 | if (flag) |
| 169 | val = 1; |
| 170 | if (!flag) |
| 171 | val = 1; |
Chandler Carruth | 584b9d6 | 2011-04-08 06:47:15 +0000 | [diff] [blame] | 172 | return val; // expected-warning{{variable 'val' may be uninitialized when used here}} |
Ted Kremenek | 13bd423 | 2011-01-20 17:37:17 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Ted Kremenek | dcfb360 | 2011-01-21 22:49:49 +0000 | [diff] [blame] | 175 | float test25() { |
Ted Kremenek | 609e317 | 2011-02-02 23:35:53 +0000 | [diff] [blame] | 176 | float x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} |
Chandler Carruth | f04eb2d | 2011-04-08 06:33:38 +0000 | [diff] [blame] | 177 | return x; // expected-warning{{variable 'x' is uninitialized when used here}} |
Ted Kremenek | dcfb360 | 2011-01-21 22:49:49 +0000 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | typedef int MyInt; |
| 181 | MyInt test26() { |
Ted Kremenek | 609e317 | 2011-02-02 23:35:53 +0000 | [diff] [blame] | 182 | MyInt x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} |
Chandler Carruth | f04eb2d | 2011-04-08 06:33:38 +0000 | [diff] [blame] | 183 | return x; // expected-warning{{variable 'x' is uninitialized when used here}} |
Ted Kremenek | dcfb360 | 2011-01-21 22:49:49 +0000 | [diff] [blame] | 184 | } |
Ted Kremenek | 9660803 | 2011-01-23 17:53:04 +0000 | [diff] [blame] | 185 | |
| 186 | // Test handling of sizeof(). |
| 187 | int test27() { |
| 188 | struct test_27 { int x; } *y; |
| 189 | return sizeof(y->x); // no-warning |
| 190 | } |
| 191 | |
| 192 | int test28() { |
Ted Kremenek | 609e317 | 2011-02-02 23:35:53 +0000 | [diff] [blame] | 193 | int len; // expected-note{{variable 'len' is declared here}} expected-note{{add initialization to silence this warning}} |
Chandler Carruth | f04eb2d | 2011-04-08 06:33:38 +0000 | [diff] [blame] | 194 | return sizeof(int[len]); // expected-warning{{variable 'len' is uninitialized when used here}} |
Ted Kremenek | 9660803 | 2011-01-23 17:53:04 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Ted Kremenek | a8c17a5 | 2011-01-25 19:13:48 +0000 | [diff] [blame] | 197 | void test29() { |
Ted Kremenek | 5533045 | 2011-02-03 06:51:50 +0000 | [diff] [blame] | 198 | int x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} |
Chandler Carruth | f04eb2d | 2011-04-08 06:33:38 +0000 | [diff] [blame] | 199 | (void) ^{ (void) x; }; // expected-warning{{variable 'x' is uninitialized when captured by block}} |
Ted Kremenek | a8c17a5 | 2011-01-25 19:13:48 +0000 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | void test30() { |
| 203 | static int x; // no-warning |
| 204 | (void) ^{ (void) x; }; |
| 205 | } |
| 206 | |
| 207 | void test31() { |
| 208 | __block int x; // no-warning |
| 209 | (void) ^{ (void) x; }; |
| 210 | } |
| 211 | |
| 212 | int test32_x; |
| 213 | void test32() { |
| 214 | (void) ^{ (void) test32_x; }; // no-warning |
| 215 | } |
| 216 | |
Ted Kremenek | dd0f794 | 2011-01-26 04:49:43 +0000 | [diff] [blame] | 217 | void test_33() { |
| 218 | int x; // no-warning |
| 219 | (void) x; |
| 220 | } |
| 221 | |
| 222 | int test_34() { |
Ted Kremenek | 609e317 | 2011-02-02 23:35:53 +0000 | [diff] [blame] | 223 | int x; // expected-note{{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} |
Ted Kremenek | dd0f794 | 2011-01-26 04:49:43 +0000 | [diff] [blame] | 224 | (void) x; |
Chandler Carruth | f04eb2d | 2011-04-08 06:33:38 +0000 | [diff] [blame] | 225 | return x; // expected-warning{{variable 'x' is uninitialized when used here}} |
Ted Kremenek | dd0f794 | 2011-01-26 04:49:43 +0000 | [diff] [blame] | 226 | } |
| 227 | |
Ted Kremenek | 40900ee | 2011-01-27 02:29:34 +0000 | [diff] [blame] | 228 | // Test that this case doesn't crash. |
| 229 | void test35(int x) { |
| 230 | __block int y = 0; |
| 231 | ^{ y = (x == 0); }(); |
| 232 | } |
| 233 | |
Ted Kremenek | 96554fd | 2011-01-27 18:51:39 +0000 | [diff] [blame] | 234 | // Test handling of indirect goto. |
| 235 | void test36() |
| 236 | { |
Ted Kremenek | 609e317 | 2011-02-02 23:35:53 +0000 | [diff] [blame] | 237 | void **pc; // expected-note{{variable 'pc' is declared here}} expected-note{{add initialization to silence this warning}} |
Ted Kremenek | 96554fd | 2011-01-27 18:51:39 +0000 | [diff] [blame] | 238 | void *dummy[] = { &&L1, &&L2 }; |
| 239 | L1: |
Chandler Carruth | 584b9d6 | 2011-04-08 06:47:15 +0000 | [diff] [blame] | 240 | goto *pc; // expected-warning{{variable 'pc' may be uninitialized when used here}} |
Ted Kremenek | 96554fd | 2011-01-27 18:51:39 +0000 | [diff] [blame] | 241 | L2: |
| 242 | goto *pc; |
| 243 | } |
| 244 | |
Ted Kremenek | 9fcbcee | 2011-02-01 17:43:18 +0000 | [diff] [blame] | 245 | // Test && nested in ||. |
| 246 | int test37_a(); |
| 247 | int test37_b(); |
| 248 | int test37() |
| 249 | { |
| 250 | int identifier; |
| 251 | if ((test37_a() && (identifier = 1)) || |
| 252 | (test37_b() && (identifier = 2))) { |
| 253 | return identifier; // no-warning |
| 254 | } |
| 255 | return 0; |
| 256 | } |
| 257 | |
| 258 | // Test merging of path-specific dataflow values (without asserting). |
| 259 | int test38(int r, int x, int y) |
| 260 | { |
| 261 | int z; |
| 262 | return ((r < 0) || ((r == 0) && (x < y))); |
| 263 | } |
| 264 | |
Ted Kremenek | f3f5379 | 2011-03-15 03:17:01 +0000 | [diff] [blame] | 265 | int test39(int x) { |
| 266 | int y; // expected-note {{variable 'y' is declared here}} expected-note{{add initialization to silence this warning}} |
Chandler Carruth | f04eb2d | 2011-04-08 06:33:38 +0000 | [diff] [blame] | 267 | int z = x + y; // expected-warning {{variable 'y' is uninitialized when used here}} |
Ted Kremenek | f3f5379 | 2011-03-15 03:17:01 +0000 | [diff] [blame] | 268 | return z; |
| 269 | } |
| 270 | |
| 271 | |
| 272 | int test40(int x) { |
| 273 | int y; // expected-note {{variable 'y' is declared here}} expected-note{{add initialization to silence this warning}} |
Chandler Carruth | f04eb2d | 2011-04-08 06:33:38 +0000 | [diff] [blame] | 274 | return x ? 1 : y; // expected-warning {{variable 'y' is uninitialized when used here}} |
Ted Kremenek | f3f5379 | 2011-03-15 03:17:01 +0000 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | int test41(int x) { |
| 278 | int y; // expected-note {{variable 'y' is declared here}} expected-note{{add initialization to silence this warning}} |
| 279 | if (x) y = 1; // no-warning |
Chandler Carruth | 584b9d6 | 2011-04-08 06:47:15 +0000 | [diff] [blame] | 280 | return y; // expected-warning {{variable 'y' may be uninitialized when used here}} |
Ted Kremenek | f3f5379 | 2011-03-15 03:17:01 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | void test42() { |
| 284 | int a; |
| 285 | a = 30; // no-warning |
| 286 | } |
| 287 | |
| 288 | void test43_aux(int x); |
| 289 | void test43(int i) { |
| 290 | int x; // expected-note {{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}} |
| 291 | for (i = 0 ; i < 10; i++) |
Chandler Carruth | 584b9d6 | 2011-04-08 06:47:15 +0000 | [diff] [blame] | 292 | test43_aux(x++); // expected-warning {{variable 'x' may be uninitialized when used here}} |
Ted Kremenek | f3f5379 | 2011-03-15 03:17:01 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | void test44(int i) { |
| 296 | int x = i; |
| 297 | int y; // expected-note {{variable 'y' is declared here}} expected-note{{add initialization to silence this warning}} |
| 298 | for (i = 0; i < 10; i++ ) { |
| 299 | test43_aux(x++); // no-warning |
Chandler Carruth | 584b9d6 | 2011-04-08 06:47:15 +0000 | [diff] [blame] | 300 | x += y; // expected-warning {{variable 'y' may be uninitialized when used here}} |
Ted Kremenek | f3f5379 | 2011-03-15 03:17:01 +0000 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | |
| 304 | int test45(int j) { |
| 305 | int x = 1, y = x + 1; |
| 306 | if (y) // no-warning |
| 307 | return x; |
| 308 | return y; |
| 309 | } |
| 310 | |
| 311 | void test46() |
| 312 | { |
| 313 | int i; // expected-note {{variable 'i' is declared here}} expected-note{{add initialization to silence this warning}} |
Chandler Carruth | f04eb2d | 2011-04-08 06:33:38 +0000 | [diff] [blame] | 314 | int j = i ? : 1; // expected-warning {{variable 'i' is uninitialized when used here}} |
Ted Kremenek | f3f5379 | 2011-03-15 03:17:01 +0000 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | void *test47(int *i) |
| 318 | { |
| 319 | return i ? : 0; // no-warning |
| 320 | } |
| 321 | |
| 322 | void *test49(int *i) |
| 323 | { |
| 324 | int a; |
| 325 | return &a ? : i; // no-warning |
| 326 | } |
| 327 | |
| 328 | void test50() |
| 329 | { |
| 330 | char c[1 ? : 2]; // no-warning |
| 331 | } |
| 332 | |
Ted Kremenek | bc8b44c | 2011-03-31 22:32:41 +0000 | [diff] [blame] | 333 | int test51(void) |
| 334 | { |
| 335 | __block int a; |
| 336 | ^(void) { |
| 337 | a = 42; |
| 338 | }(); |
| 339 | return a; // no-warning |
| 340 | } |
| 341 | |
Ted Kremenek | e6c2803 | 2011-05-10 22:10:35 +0000 | [diff] [blame] | 342 | // FIXME: This is a false positive, but it tests logical operations in switch statements. |
| 343 | int test52(int a, int b) { |
| 344 | int x; // expected-note {{variable 'x' is declared here}} expected-note {{add initialization to silence this warning}} |
| 345 | switch (a || b) { // expected-warning {{switch condition has boolean value}} |
| 346 | case 0: |
| 347 | x = 1; |
| 348 | break; |
| 349 | case 1: |
| 350 | x = 2; |
| 351 | break; |
| 352 | } |
| 353 | return x; // expected-warning {{variable 'x' may be uninitialized when used here}} |
| 354 | } |