blob: 37a6f75b3ca2164093883ec5f8849ad2e338cb1c [file] [log] [blame]
Ted Kremenek51885072011-03-24 00:28:47 +00001// 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 Rose23b736e2010-07-29 07:11:59 +00003
4int 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 Rose59b6dca2010-08-20 01:05:59 +000026
27void 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
38void 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}