1 // RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-config eagerly-assume=false -analyzer-checker=core.uninitialized.Assign,debug.ExprInspection -verify %s
3 void clang_analyzer_eval(int);
6 const union { float a
; } u
= {};
10 int const parr
[2] = {1};
13 clang_analyzer_eval(parr
[i
]); // expected-warning{{UNDEFINED}}
15 clang_analyzer_eval(parr
[i
] == 0); // expected-warning{{TRUE}}
17 clang_analyzer_eval(parr
[i
]); // expected-warning{{UNDEFINED}}
24 const struct SM sm
= {.a
= 1};
26 clang_analyzer_eval(sm
.a
== 1); // expected-warning{{TRUE}}
27 clang_analyzer_eval(sm
.b
== 0); // expected-warning{{TRUE}}
30 const int glob_arr1
[6] = {[2] = 3, [0] = 1, [1] = 2, [3] = 4};
31 void glob_array_index1(void) {
32 clang_analyzer_eval(glob_arr1
[0] == 1); // expected-warning{{TRUE}}
33 clang_analyzer_eval(glob_arr1
[1] == 2); // expected-warning{{TRUE}}
34 clang_analyzer_eval(glob_arr1
[2] == 3); // expected-warning{{TRUE}}
35 clang_analyzer_eval(glob_arr1
[3] == 4); // expected-warning{{TRUE}}
36 clang_analyzer_eval(glob_arr1
[4] == 0); // expected-warning{{TRUE}}
37 clang_analyzer_eval(glob_arr1
[5] == 0); // expected-warning{{TRUE}}
40 void glob_array_index2(void) {
41 const int *ptr
= glob_arr1
;
42 clang_analyzer_eval(ptr
[0] == 1); // expected-warning{{TRUE}}
43 clang_analyzer_eval(ptr
[1] == 2); // expected-warning{{TRUE}}
44 clang_analyzer_eval(ptr
[2] == 3); // expected-warning{{TRUE}}
45 clang_analyzer_eval(ptr
[3] == 4); // expected-warning{{TRUE}}
46 clang_analyzer_eval(ptr
[4] == 0); // expected-warning{{TRUE}}
47 clang_analyzer_eval(ptr
[5] == 0); // expected-warning{{TRUE}}
50 void glob_invalid_index1(void) {
52 int res
= glob_arr1
[x
]; // expected-warning{{garbage or undefined}}
55 void glob_invalid_index2(void) {
56 const int *ptr
= glob_arr1
;
58 int res
= ptr
[x
]; // expected-warning{{garbage or undefined}}
61 const int glob_arr2
[3][3] = {[0][0] = 1, [1][1] = 5, [2][0] = 7};
62 void glob_arr_index3(void) {
63 clang_analyzer_eval(glob_arr2
[0][0] == 1); // expected-warning{{TRUE}}
64 clang_analyzer_eval(glob_arr2
[0][1] == 0); // expected-warning{{TRUE}}
65 clang_analyzer_eval(glob_arr2
[0][2] == 0); // expected-warning{{TRUE}}
66 clang_analyzer_eval(glob_arr2
[1][0] == 0); // expected-warning{{TRUE}}
67 clang_analyzer_eval(glob_arr2
[1][1] == 5); // expected-warning{{TRUE}}
68 clang_analyzer_eval(glob_arr2
[1][2] == 0); // expected-warning{{TRUE}}
69 clang_analyzer_eval(glob_arr2
[2][0] == 7); // expected-warning{{TRUE}}
70 clang_analyzer_eval(glob_arr2
[2][1] == 0); // expected-warning{{TRUE}}
71 clang_analyzer_eval(glob_arr2
[2][2] == 0); // expected-warning{{TRUE}}
74 void negative_index(void) {
76 clang_analyzer_eval(glob_arr2
[x
][y
] == 5); // expected-warning{{UNDEFINED}}
79 clang_analyzer_eval(glob_arr2
[x
][y
] == 7); // expected-warning{{UNDEFINED}}
82 void glob_invalid_index3(void) {
84 int res
= glob_arr2
[x
][y
]; // expected-warning{{garbage or undefined}}
87 void glob_invalid_index4(void) {
89 int res
= glob_arr2
[x
][y
]; // expected-warning{{garbage or undefined}}
92 const int glob_arr_no_init
[10];
93 void glob_arr_index4(void) {
94 // FIXME: Should warn {{FALSE}}, since the array has a static storage.
95 clang_analyzer_eval(glob_arr_no_init
[2]); // expected-warning{{UNKNOWN}}
98 const int glob_arr3
[]; // IncompleteArrayType
99 const int glob_arr3
[4] = {1, 2, 3}; // ConstantArrayType
100 void glob_arr_index5(void) {
101 clang_analyzer_eval(glob_arr3
[0] == 1); // expected-warning{{TRUE}}
102 clang_analyzer_eval(glob_arr3
[1] == 2); // expected-warning{{TRUE}}
103 clang_analyzer_eval(glob_arr3
[2] == 3); // expected-warning{{TRUE}}
104 clang_analyzer_eval(glob_arr3
[3] == 0); // expected-warning{{TRUE}}
107 void glob_invalid_index5(void) {
109 int res
= glob_arr3
[x
]; // expected-warning{{garbage or undefined}}
112 void glob_invalid_index6(void) {
114 int res
= glob_arr3
[x
]; // expected-warning{{garbage or undefined}}
117 const int glob_arr4
[]; // IncompleteArrayType
118 const int glob_arr4
[4] = {1, 2, 3}; // ConstantArrayType
119 const int glob_arr4
[]; // ConstantArrayType (according to AST)
120 void glob_arr_index6(void) {
121 clang_analyzer_eval(glob_arr4
[0] == 1); // expected-warning{{TRUE}}
122 clang_analyzer_eval(glob_arr4
[1] == 2); // expected-warning{{TRUE}}
123 clang_analyzer_eval(glob_arr4
[2] == 3); // expected-warning{{TRUE}}
124 clang_analyzer_eval(glob_arr4
[3] == 0); // expected-warning{{TRUE}}
127 void glob_invalid_index7(void) {
129 int res
= glob_arr4
[x
]; // expected-warning{{garbage or undefined}}
132 void glob_invalid_index8(void) {
134 int res
= glob_arr4
[x
]; // expected-warning{{garbage or undefined}}