Ted Kremenek | 5188507 | 2011-03-24 00:28:47 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -analyze -analyzer-checker=core,core.experimental,deadcode.experimental.UnreachableCode -analyzer-store=region -analyzer-constraints=basic -verify %s |
| 2 | // RUN: %clang_cc1 -analyze -analyzer-checker=core,core.experimental,deadcode.experimental.UnreachableCode -analyzer-store=region -analyzer-constraints=range -verify %s |
Jordy Rose | 23b736e | 2010-07-29 07:11:59 +0000 | [diff] [blame] | 3 | |
| 4 | int string_literal_init() { |
| 5 | char a[] = "abc"; |
| 6 | char b[2] = "abc"; // expected-warning{{too long}} |
| 7 | char c[5] = "abc"; |
| 8 | |
| 9 | if (a[1] != 'b') |
| 10 | return 0; // expected-warning{{never executed}} |
| 11 | if (b[1] != 'b') |
| 12 | return 0; // expected-warning{{never executed}} |
| 13 | if (c[1] != 'b') |
| 14 | return 0; // expected-warning{{never executed}} |
| 15 | |
| 16 | if (a[3] != 0) |
| 17 | return 0; // expected-warning{{never executed}} |
| 18 | if (c[3] != 0) |
| 19 | return 0; // expected-warning{{never executed}} |
| 20 | |
| 21 | if (c[4] != 0) |
| 22 | return 0; // expected-warning{{never executed}} |
| 23 | |
| 24 | return 42; |
| 25 | } |
Jordy Rose | 59b6dca | 2010-08-20 01:05:59 +0000 | [diff] [blame] | 26 | |
| 27 | void nested_compound_literals(int rad) { |
| 28 | int vec[6][2] = {{0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, |
| 29 | {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}}; |
| 30 | int a; |
| 31 | |
| 32 | for (a = 0; a < 6; ++a) { |
| 33 | vec[a][0] *= rad; // no-warning |
| 34 | vec[a][1] *= rad; // no-warning |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | void nested_compound_literals_float(float rad) { |
| 39 | float vec[6][2] = {{0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, |
| 40 | {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}}; |
| 41 | int a; |
| 42 | |
| 43 | for (a = 0; a < 6; ++a) { |
| 44 | vec[a][0] *= rad; // no-warning |
| 45 | vec[a][1] *= rad; // no-warning |
| 46 | } |
| 47 | } |