Debian Codegraph @

gcc/testsuite/c-c++-common/analyzer/uninit-1.c

raw
1 #include "analyzer-decls.h"
2 typedef __SIZE_TYPE__ size_t;
3
4 int test_1 (void)
5 {
6 int i; /* { dg-message "region created on stack here" } */
7 return i; /* { dg-warning "use of uninitialized value 'i'" } */
8 }
9
10 int test_2 (void)
11 {
12 int i; /* { dg-message "region created on stack here" } */
13 return i * 2; /* { dg-warning "use of uninitialized value 'i'" } */
14 }
15
16 int test_3 (void)
17 {
18 static int i;
19 return i;
20 }
21
22 int test_4 (void)
23 {
24 int *p; /* { dg-message "region created on stack here" } */
25 return *p; /* { dg-warning "use of uninitialized value 'p'" } */
26 }
27
28 int test_5 (int flag, int *q)
29 {
30 int *p; /* { dg-message "region created on stack here" } */
31 if (flag) /* { dg-message "following 'false' branch" } */
32 p = q;
33
34 /* There should be two enodes here,
35 i.e. not merging the init vs non-init states. */
36 __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
37
38 return *p; /* { dg-warning "use of uninitialized value 'p'" } */
39 }
40
41 int test_6 (int i)
42 {
43 int arr[10]; /* { dg-message "region created on stack here" } */
44 return arr[i]; /* { dg-warning "use of uninitialized value 'arr\\\[i\\\]'" } */
45 }
46
47 int test_rshift_rhs (int i)
48 {
49 int j; /* { dg-message "region created on stack here" } */
50 return i >> j; /* { dg-warning "use of uninitialized value 'j'" } */
51 }
52
53 int test_lshift_rhs (int i)
54 {
55 int j; /* { dg-message "region created on stack here" } */
56 return i << j; /* { dg-warning "use of uninitialized value 'j'" } */
57 }
58
59 int test_rshift_lhs (int i)
60 {
61 int j; /* { dg-message "region created on stack here" } */
62 return j >> i; /* { dg-warning "use of uninitialized value 'j'" } */
63 }
64
65 int test_lshift_lhs (int i)
66 {
67 int j; /* { dg-message "region created on stack here" } */
68 return j << i; /* { dg-warning "use of uninitialized value 'j'" } */
69 }
70
71 int test_cmp (int i)
72 {
73 int j; /* { dg-message "region created on stack here" } */
74 return i < j; /* { dg-warning "use of uninitialized value 'j'" } */
75 }
76
77 float test_plus_rhs (float x)
78 {
79 float y; /* { dg-message "region created on stack here" } */
80 return x + y; /* { dg-warning "use of uninitialized value 'y'" } */
81 }
82
83 float test_plus_lhs (float x)
84 {
85 float y; /* { dg-message "region created on stack here" } */
86 return y + x; /* { dg-warning "use of uninitialized value 'y'" } */
87 }
88
89 float test_minus_rhs (float x)
90 {
91 float y; /* { dg-message "region created on stack here" } */
92 return x - y; /* { dg-warning "use of uninitialized value 'y'" } */
93 }
94
95 float test_minus_lhs (float x)
96 {
97 float y; /* { dg-message "region created on stack here" } */
98 return y - x; /* { dg-warning "use of uninitialized value 'y'" } */
99 }
100
101 float test_times_rhs (float x)
102 {
103 float y; /* { dg-message "region created on stack here" } */
104 return x * y; /* { dg-warning "use of uninitialized value 'y'" } */
105 }
106
107 float test_times_lhs (float x)
108 {
109 float y; /* { dg-message "region created on stack here" } */
110 return y * x; /* { dg-warning "use of uninitialized value 'y'" } */
111 }
112
113 float test_divide_rhs (float x)
114 {
115 float y; /* { dg-message "region created on stack here" } */
116 return x / y; /* { dg-warning "use of uninitialized value 'y'" } */
117 }
118
119 float test_divide_lhs (float x)
120 {
121 float y; /* { dg-message "region created on stack here" } */
122 return y / x; /* { dg-warning "use of uninitialized value 'y'" } */
123 }
124
125 size_t test_builtin_strlen (void)
126 {
127 const char *ptr; /* { dg-message "region created on stack here" } */
128 return __builtin_strlen (ptr); /* { dg-warning "use of uninitialized value 'ptr'" } */
129 }
130
131 void test_calling_uninit_fn_ptr_1 (void)
132 {
133 void (*fn_ptr) (void); /* { dg-message "region created on stack here" } */
134 fn_ptr (); /* { dg-warning "use of uninitialized value 'fn_ptr'" } */
135 }
136
137 int test_calling_uninit_fn_ptr_2 (void)
138 {
139 int (*fn_ptr) (void); /* { dg-message "region created on stack here" } */
140 return fn_ptr (); /* { dg-warning "use of uninitialized value 'fn_ptr'" } */
141 }
142
143 extern void called_by_uninit_arg (int);
144 void test_passing_uninit_arg (void)
145 {
146 int i; /* { dg-message "region created on stack here" } */
147 called_by_uninit_arg (i); /* { dg-warning "use of uninitialized value 'i'" } */
148 }