[AMDGPU][AsmParser][NFC] Get rid of custom default operand handlers.
[llvm-project.git] / clang / test / Analysis / initialization.c
blobd394a902ffeb78c823072cc6f07695ec08cbc87a
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);
5 void initbug(void) {
6 const union { float a; } u = {};
7 (void)u.a; // no-crash
10 int const parr[2] = {1};
11 void constarr(void) {
12 int i = 2;
13 clang_analyzer_eval(parr[i]); // expected-warning{{UNDEFINED}}
14 i = 1;
15 clang_analyzer_eval(parr[i] == 0); // expected-warning{{TRUE}}
16 i = -1;
17 clang_analyzer_eval(parr[i]); // expected-warning{{UNDEFINED}}
20 struct SM {
21 int a;
22 int b;
24 const struct SM sm = {.a = 1};
25 void multinit(void) {
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) {
51 int x = -42;
52 int res = glob_arr1[x]; // expected-warning{{garbage or undefined}}
55 void glob_invalid_index2(void) {
56 const int *ptr = glob_arr1;
57 int x = 42;
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) {
75 int x = 2, y = -2;
76 clang_analyzer_eval(glob_arr2[x][y] == 5); // expected-warning{{UNDEFINED}}
77 x = 3;
78 y = -3;
79 clang_analyzer_eval(glob_arr2[x][y] == 7); // expected-warning{{UNDEFINED}}
82 void glob_invalid_index3(void) {
83 int x = -1, y = -1;
84 int res = glob_arr2[x][y]; // expected-warning{{garbage or undefined}}
87 void glob_invalid_index4(void) {
88 int x = 3, y = 2;
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) {
108 int x = 42;
109 int res = glob_arr3[x]; // expected-warning{{garbage or undefined}}
112 void glob_invalid_index6(void) {
113 int x = -42;
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) {
128 int x = 42;
129 int res = glob_arr4[x]; // expected-warning{{garbage or undefined}}
132 void glob_invalid_index8(void) {
133 int x = -42;
134 int res = glob_arr4[x]; // expected-warning{{garbage or undefined}}