1 /* { dg-additional-options "-fno-analyzer-suppress-followups" } */
2
3 #include <stdio.h>
4
5 struct test {
6 int one;
7 int two;
8 };
9
10 void func2(const struct test *t)
11 {
12 if (t->one == 0)
13 printf("init func2\n");
14
15 if (t->two == 0) /* { dg-warning "uninitialized" } */
16 printf("uninit func2\n");
17 }
18
19 void func1(struct test *t)
20 {
21 t->one = 1;
22 func2(t);
23 }
24
25 int func3(int num)
26 {
27 if (num)
28 return num;
29 else
30 return 0;
31 }
32
33 void func4(int *a, int max)
34 {
35 int i;
36 // skip the first
37 for (i=1; i<max; i++)
38 a[i] = 0;
39 }
40
41 void func5(const int *a, int max)
42 {
43 /* a[0] is uninitialized, but the rest of the array is initialized. */
44 int i;
45 for (i=0; i<max; i++) {
46 if (a[i]) /* { dg-warning "uninitialized" "" { xfail *-*-* } } */
47 printf("func5: %d\n", i);
48 }
49 }
50
51 int func6(const int *num)
52 {
53 if (*num) /* { dg-warning "uninitialized" } */
54 return *num; /* { dg-warning "uninitialized" } */
55 else
56 return 0;
57 }
58
59 int j;
60 int func7(void)
61 {
62 return j; /* { dg-bogus "uninitialized" } */
63 }
64
65 void func8(const int *a, int max)
66 {
67 int i;
68 for (i=0; i<max; i++) {
69 if (a[i]) /* { dg-warning "uninitialized" } */
70 printf("func8: %d\n", i);
71 }
72 }
73
74 enum {RED, AMBER, GREEN, BLACK};
75
76 int main(void)
77 {
78 struct test t; /* { dg-message "region created on stack here" } */
79 int num; /* { dg-message "region created on stack here" } */
80 int arry[10];
81 int arry_2[10]; /* { dg-message "region created on stack here" } */
82 int go; /* { dg-message "region created on stack here" } */
83 int color = BLACK;
84
85 func1(&t);
86 func3(num); /* { dg-warning "use of uninitialized value 'num'" } */
87 func4(arry, 10);
88 func5(arry, 10);
89 func6(&num);
90
91 printf("num: %d\n", num); /* { dg-warning "use of uninitialized value 'num'" } */
92 printf("func7: %d\n", func7());
93 func8(arry_2, 10);
94
95 switch (color) {
96 case RED:
97 case AMBER:
98 go = 0;
99 break;
100 case GREEN:
101 go = 1;
102 break;
103 }
104
105 printf("go :%d\n", go); /* { dg-warning "use of uninitialized value 'go'" } */
106
107 return 0;
108 }