Debian Codegraph @

gcc/testsuite/gcc.dg/analyzer/symbolic-9.c

raw
1 #include "analyzer-decls.h"
2
3 struct st
4 {
5 void *ptr[10];
6 int arr[10];
7 };
8
9 /* Various combinations of a pair of writes, involving
10 symbolic vs concrete clusters, with symbolic vs concrete keys
11 within them. */
12
13 struct st g;
14
15 /* "ptr" write: fully concrete. */
16
17 struct st
18 test_conc_conc_ptr_conc_conc_arr (void)
19 {
20 struct st s;
21 s.ptr[1] = __builtin_malloc (1024);
22 __analyzer_describe (0, s.ptr[1]); /* { dg-warning "HEAP_ALLOCATED_REGION" } */
23 s.arr[5] = 42;
24 __analyzer_describe (0, s.ptr[1]); /* { dg-warning "HEAP_ALLOCATED_REGION" } */
25 __analyzer_describe (0, s.arr[5]); /* { dg-warning "42" } */
26 return s;
27 }
28
29 struct st
30 test_conc_conc_ptr_conc_sym_arr (int j)
31 {
32 struct st s;
33 s.ptr[1] = __builtin_malloc (1024);
34 __analyzer_describe (0, s.ptr[1]); /* { dg-warning "HEAP_ALLOCATED_REGION" } */
35 s.arr[j] = 42;
36 __analyzer_describe (0, s.ptr[1]); /* { dg-warning "UNKNOWN" } */
37 __analyzer_describe (0, s.arr[j]); /* { dg-warning "42" } */
38 return s;
39 }
40
41 struct st
42 test_conc_conc_ptr_sym_conc_arr (struct st *p)
43 {
44 struct st s;
45 s.ptr[1] = __builtin_malloc (1024);
46 __analyzer_describe (0, s.ptr[1]); /* { dg-warning "HEAP_ALLOCATED_REGION" } */
47 p->arr[5] = 42;
48 __analyzer_describe (0, s.ptr[1]); /* { dg-warning "HEAP_ALLOCATED_REGION" } */
49 __analyzer_describe (0, p->arr[5]); /* { dg-warning "42" } */
50 return s;
51 }
52
53 struct st
54 test_conc_conc_ptr_sym_sym_arr (struct st *p, int j)
55 {
56 struct st s;
57 s.ptr[1] = __builtin_malloc (1024);
58 __analyzer_describe (0, s.ptr[1]); /* { dg-warning "HEAP_ALLOCATED_REGION" } */
59 p->arr[j] = 42;
60 __analyzer_describe (0, s.ptr[1]); /* { dg-warning "HEAP_ALLOCATED_REGION" } */
61 __analyzer_describe (0, p->arr[j]); /* { dg-warning "42" } */
62 return s;
63 }
64
65 /* "ptr" write: symbolic region, but at concrete offset. */
66
67 void
68 test_sym_conc_ptr_conc_conc_arr (struct st *p)
69 {
70 p->ptr[1] = __builtin_malloc (1024);
71 __analyzer_describe (0, p->ptr[1]); /* { dg-warning "HEAP_ALLOCATED_REGION" } */
72 g.arr[5] = 42;
73 __analyzer_describe (0, p->ptr[1]); /* { dg-warning "UNKNOWN" } */
74 __analyzer_describe (0, g.arr[5]); /* { dg-warning "42" } */
75 }
76
77 void
78 test_sym_conc_ptr_conc_sym_arr (struct st *p, int j)
79 {
80 p->ptr[1] = __builtin_malloc (1024);
81 __analyzer_describe (0, p->ptr[1]); /* { dg-warning "HEAP_ALLOCATED_REGION" } */
82 g.arr[j] = 42;
83 __analyzer_describe (0, p->ptr[1]); /* { dg-warning "UNKNOWN" } */
84 __analyzer_describe (0, g.arr[j]); /* { dg-warning "42" } */
85 }
86
87 void
88 test_sym_conc_ptr_sym_conc_arr (struct st *p, struct st *q)
89 {
90 p->ptr[1] = __builtin_malloc (1024);
91 __analyzer_describe (0, p->ptr[1]); /* { dg-warning "HEAP_ALLOCATED_REGION" } */
92 q->arr[5] = 42;
93 __analyzer_describe (0, p->ptr[1]); /* { dg-warning "UNKNOWN" } */
94 __analyzer_describe (0, q->arr[5]); /* { dg-warning "42" } */
95 }
96
97 void
98 test_sym_conc_ptr_sym_sym_arr (struct st *p, struct st *q, int j)
99 {
100 p->ptr[1] = __builtin_malloc (1024);
101 __analyzer_describe (0, p->ptr[1]); /* { dg-warning "HEAP_ALLOCATED_REGION" } */
102 q->arr[j] = 42;
103 __analyzer_describe (0, p->ptr[1]); /* { dg-warning "UNKNOWN" } */
104 __analyzer_describe (0, q->arr[j]); /* { dg-warning "42" } */
105 }
106
107 /* "ptr" write: concrete region, but at symbolic offset. */
108
109 struct st
110 test_conc_sym_ptr_conc_conc_arr (int i)
111 {
112 struct st s;
113 s.ptr[i] = __builtin_malloc (1024);
114 __analyzer_describe (0, s.ptr[i]); /* { dg-warning "HEAP_ALLOCATED_REGION" } */
115 s.arr[5] = 42;
116 __analyzer_describe (0, s.ptr[i]); /* { dg-warning "UNKNOWN" } */
117 __analyzer_describe (0, s.arr[5]); /* { dg-warning "42" } */
118 return s;
119 }
120
121 struct st
122 test_conc_sym_ptr_conc_sym_arr (int i, int j)
123 {
124 struct st s;
125 s.ptr[i] = __builtin_malloc (1024);
126 __analyzer_describe (0, s.ptr[i]); /* { dg-warning "HEAP_ALLOCATED_REGION" } */
127 s.arr[j] = 42;
128 __analyzer_describe (0, s.ptr[i]); /* { dg-warning "UNKNOWN" } */
129 __analyzer_describe (0, s.arr[j]); /* { dg-warning "42" } */
130 return s;
131 }
132
133 struct st
134 test_conc_sym_ptr_sym_conc_arr (int i, struct st *p)
135 {
136 struct st s;
137 s.ptr[i] = __builtin_malloc (1024);
138 __analyzer_describe (0, s.ptr[i]); /* { dg-warning "HEAP_ALLOCATED_REGION" } */
139 p->arr[5] = 42;
140 __analyzer_describe (0, s.ptr[i]); /* { dg-warning "HEAP_ALLOCATED_REGION" } */
141 __analyzer_describe (0, p->arr[5]); /* { dg-warning "42" } */
142 return s;
143 } /* { dg-bogus "leak" "PR analyzer/105190" { xfail *-*-* } } */
144
145 struct st
146 test_conc_sym_ptr_sym_sym_arr (int i, struct st *p, int j)
147 {
148 struct st s;
149 s.ptr[i] = __builtin_malloc (1024);
150 __analyzer_describe (0, s.ptr[i]); /* { dg-warning "HEAP_ALLOCATED_REGION" } */
151 p->arr[j] = 42;
152 __analyzer_describe (0, s.ptr[i]); /* { dg-warning "HEAP_ALLOCATED_REGION" } */
153 __analyzer_describe (0, p->arr[j]); /* { dg-warning "42" } */
154 return s;
155 } /* { dg-bogus "leak" "PR analyzer/105190" { xfail *-*-* } } */
156
157 /* "ptr" write: symbolic region, with symbolic offset. */
158
159 void
160 test_sym_sym_ptr_conc_conc_arr (struct st *p, int i)
161 {
162 p->ptr[i] = __builtin_malloc (1024);
163 __analyzer_describe (0, p->ptr[i]); /* { dg-warning "HEAP_ALLOCATED_REGION" } */
164 g.arr[5] = 42;
165 __analyzer_describe (0, p->ptr[i]); /* { dg-warning "UNKNOWN" } */
166 __analyzer_describe (0, g.arr[5]); /* { dg-warning "42" } */
167 }
168
169 void
170 test_sym_sym_ptr_conc_sym_arr (struct st *p, int i, int j)
171 {
172 p->ptr[i] = __builtin_malloc (1024);
173 __analyzer_describe (0, p->ptr[i]); /* { dg-warning "HEAP_ALLOCATED_REGION" } */
174 g.arr[j] = 42;
175 __analyzer_describe (0, p->ptr[i]); /* { dg-warning "UNKNOWN" } */
176 __analyzer_describe (0, g.arr[j]); /* { dg-warning "42" } */
177 }
178
179 void
180 test_sym_sym_ptr_sym_conc_arr (struct st *p, int i, struct st *q)
181 {
182 p->ptr[i] = __builtin_malloc (1024);
183 __analyzer_describe (0, p->ptr[i]); /* { dg-warning "HEAP_ALLOCATED_REGION" } */
184 q->arr[5] = 42;
185 __analyzer_describe (0, p->ptr[i]); /* { dg-warning "UNKNOWN" } */
186 __analyzer_describe (0, q->arr[5]); /* { dg-warning "42" } */
187 }
188
189 void
190 test_sym_sym_ptr_sym_sym_arr (struct st *p, int i, struct st *q, int j)
191 {
192 p->ptr[i] = __builtin_malloc (1024);
193 __analyzer_describe (0, p->ptr[i]); /* { dg-warning "HEAP_ALLOCATED_REGION" } */
194 q->arr[j] = 42;
195 __analyzer_describe (0, p->ptr[i]); /* { dg-warning "UNKNOWN" } */
196 __analyzer_describe (0, q->arr[j]); /* { dg-warning "42" } */
197 }