Ted Kremenek | 033a07e | 2011-08-03 23:14:55 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -analyze -analyzer-checker=core,experimental.core,experimental.deadcode.UnreachableCode -analyzer-store=region -analyzer-constraints=basic -verify %s |
| 2 | // RUN: %clang_cc1 -analyze -analyzer-checker=core,experimental.core,experimental.deadcode.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) { |
David Blaikie | e31b8fb | 2012-04-05 00:16:44 +0000 | [diff] [blame] | 28 | int vec[6][2] = {{0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, // expected-warning 6 {{implicit conversion turns literal floating-point number into integer}} |
| 29 | {0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}}; // expected-warning 6 {{implicit conversion turns literal floating-point number into integer}} |
Jordy Rose | 59b6dca | 2010-08-20 01:05:59 +0000 | [diff] [blame] | 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 | } |
Jordy Rose | f113940 | 2012-05-12 17:32:59 +0000 | [diff] [blame] | 48 | |
| 49 | |
| 50 | void struct_as_array() { |
| 51 | struct simple { int x; }; |
| 52 | struct simple a; |
| 53 | struct simple *p = &a; |
| 54 | p->x = 5; |
| 55 | if (!p[0].x) |
| 56 | return; // expected-warning{{never executed}} |
| 57 | if (p[0].x) |
| 58 | return; // no-warning |
| 59 | } |
| 60 | |