Debian Codegraph @

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

raw
1 /* { dg-additional-options "-fdiagnostics-show-line-numbers -fdiagnostics-path-format=inline-events -fdiagnostics-show-caret -fanalyzer-verbosity=1" } */
2 /* { dg-skip-if "requires hosted libstdc++ for stdlib free" { ! hostedlib } } */
3 /* { dg-enable-nn-line-numbers "" } */
4
5 #include <stdlib.h>
6
7 void calls_free_1 (void *ptr)
8 {
9 free (ptr); /* { dg-warning "double-'free' of 'ptr'" } */
10 }
11
12 void test_1 (void *ptr, int a, int b)
13 {
14 if (a)
15 calls_free_1 (ptr);
16
17 if (b)
18 {
19 }
20 else
21 calls_free_1 (ptr);
22 }
23
24 /* { dg-begin-multiline-output "" }
25 NN | free (ptr);
26 | ^~~~~~~~~~
27 'test_1': events 1-2
28 |
29 | NN | void test_1 (void *ptr, int a, int b)
30 | | ^~~~~~
31 | | |
32 | | (1) entry to 'test_1'
33 |......
34 | NN | calls_free_1 (ptr);
35 | | ~~~~~~~~~~~~~~~~~~
36 | | |
37 | | (2) calling 'calls_free_1' from 'test_1'
38 |
39 +--> 'calls_free_1': events 3-4
40 |
41 | NN | void calls_free_1 (void *ptr)
42 | | ^~~~~~~~~~~~
43 | | |
44 | | (3) entry to 'calls_free_1'
45 | NN | {
46 | NN | free (ptr);
47 | | ~~~~~~~~~~
48 | | |
49 | | (4) first 'free' here
50 |
51 <------+
52 |
53 'test_1': events 5-6
54 |
55 | NN | calls_free_1 (ptr);
56 | | ^~~~~~~~~~~~~~~~~~
57 | | |
58 | | (5) returning to 'test_1' from 'calls_free_1'
59 |......
60 | NN | calls_free_1 (ptr);
61 | | ~~~~~~~~~~~~~~~~~~
62 | | |
63 | | (6) passing freed pointer 'ptr' in call to 'calls_free_1' from 'test_1'
64 |
65 +--> 'calls_free_1': events 7-8
66 |
67 | NN | void calls_free_1 (void *ptr)
68 | | ^~~~~~~~~~~~
69 | | |
70 | | (7) entry to 'calls_free_1'
71 | NN | {
72 | NN | free (ptr);
73 | | ~~~~~~~~~~
74 | | |
75 | | (8) second 'free' here; first 'free' was at (4)
76 |
77 { dg-end-multiline-output "" { target c } } */
78 /* { dg-begin-multiline-output "" }
79 NN | free (ptr);
80 | ~~~~~^~~~~
81 'void test_1(void*, int, int)': events 1-2
82 |
83 | NN | void test_1 (void *ptr, int a, int b)
84 | | ^~~~~~
85 | | |
86 | | (1) entry to 'test_1'
87 |......
88 | NN | calls_free_1 (ptr);
89 | | ~~~~~~~~~~~~~~~~~~
90 | | |
91 | | (2) calling 'calls_free_1' from 'test_1'
92 |
93 +--> 'void calls_free_1(void*)': events 3-4
94 |
95 | NN | void calls_free_1 (void *ptr)
96 | | ^~~~~~~~~~~~
97 | | |
98 | | (3) entry to 'calls_free_1'
99 | NN | {
100 | NN | free (ptr);
101 | | ~~~~~~~~~~
102 | | |
103 | | (4) first 'free' here
104 |
105 <------+
106 |
107 'void test_1(void*, int, int)': events 5-6
108 |
109 | NN | calls_free_1 (ptr);
110 | | ~~~~~~~~~~~~~^~~~~
111 | | |
112 | | (5) returning to 'test_1' from 'calls_free_1'
113 |......
114 | NN | calls_free_1 (ptr);
115 | | ~~~~~~~~~~~~~~~~~~
116 | | |
117 | | (6) passing freed pointer 'ptr' in call to 'calls_free_1' from 'test_1'
118 |
119 +--> 'void calls_free_1(void*)': events 7-8
120 |
121 | NN | void calls_free_1 (void *ptr)
122 | | ^~~~~~~~~~~~
123 | | |
124 | | (7) entry to 'calls_free_1'
125 | NN | {
126 | NN | free (ptr);
127 | | ~~~~~~~~~~
128 | | |
129 | | (8) second 'free' here; first 'free' was at (4)
130 |
131 { dg-end-multiline-output "" { target c++ } } */
132
133 void calls_free_2 (void *ptr)
134 {
135 free (ptr); /* { dg-warning "double-'free' of 'ptr'" } */
136 }
137
138 void test_2 (void *ptr, int a, int b)
139 {
140 switch (a)
141 {
142 default:
143 break;
144 case 1:
145 break;
146 case 3:
147 calls_free_2 (ptr);
148 break;
149 }
150
151 switch (b)
152 {
153 default:
154 calls_free_2 (ptr);
155 break;
156 case 1:
157 break;
158 case 42:
159 break;
160 }
161 }
162
163 /* { dg-begin-multiline-output "" }
164 NN | free (ptr);
165 | ^~~~~~~~~~
166 'test_2': events 1-2
167 |
168 | NN | void test_2 (void *ptr, int a, int b)
169 | | ^~~~~~
170 | | |
171 | | (1) entry to 'test_2'
172 |......
173 | NN | calls_free_2 (ptr);
174 | | ~~~~~~~~~~~~~~~~~~
175 | | |
176 | | (2) calling 'calls_free_2' from 'test_2'
177 |
178 +--> 'calls_free_2': events 3-4
179 |
180 | NN | void calls_free_2 (void *ptr)
181 | | ^~~~~~~~~~~~
182 | | |
183 | | (3) entry to 'calls_free_2'
184 | NN | {
185 | NN | free (ptr);
186 | | ~~~~~~~~~~
187 | | |
188 | | (4) first 'free' here
189 |
190 <------+
191 |
192 'test_2': events 5-6
193 |
194 | NN | calls_free_2 (ptr);
195 | | ^~~~~~~~~~~~~~~~~~
196 | | |
197 | | (5) returning to 'test_2' from 'calls_free_2'
198 |......
199 | NN | calls_free_2 (ptr);
200 | | ~~~~~~~~~~~~~~~~~~
201 | | |
202 | | (6) passing freed pointer 'ptr' in call to 'calls_free_2' from 'test_2'
203 |
204 +--> 'calls_free_2': events 7-8
205 |
206 | NN | void calls_free_2 (void *ptr)
207 | | ^~~~~~~~~~~~
208 | | |
209 | | (7) entry to 'calls_free_2'
210 | NN | {
211 | NN | free (ptr);
212 | | ~~~~~~~~~~
213 | | |
214 | | (8) second 'free' here; first 'free' was at (4)
215 |
216 { dg-end-multiline-output "" { target c } } */
217 /* { dg-begin-multiline-output "" }
218 NN | free (ptr);
219 | ~~~~~^~~~~
220 'void test_2(void*, int, int)': events 1-2
221 |
222 | NN | void test_2 (void *ptr, int a, int b)
223 | | ^~~~~~
224 | | |
225 | | (1) entry to 'test_2'
226 |......
227 | NN | calls_free_2 (ptr);
228 | | ~~~~~~~~~~~~~~~~~~
229 | | |
230 | | (2) calling 'calls_free_2' from 'test_2'
231 |
232 +--> 'void calls_free_2(void*)': events 3-4
233 |
234 | NN | void calls_free_2 (void *ptr)
235 | | ^~~~~~~~~~~~
236 | | |
237 | | (3) entry to 'calls_free_2'
238 | NN | {
239 | NN | free (ptr);
240 | | ~~~~~~~~~~
241 | | |
242 | | (4) first 'free' here
243 |
244 <------+
245 |
246 'void test_2(void*, int, int)': events 5-6
247 |
248 | NN | calls_free_2 (ptr);
249 | | ~~~~~~~~~~~~~^~~~~
250 | | |
251 | | (5) returning to 'test_2' from 'calls_free_2'
252 |......
253 | NN | calls_free_2 (ptr);
254 | | ~~~~~~~~~~~~~~~~~~
255 | | |
256 | | (6) passing freed pointer 'ptr' in call to 'calls_free_2' from 'test_2'
257 |
258 +--> 'void calls_free_2(void*)': events 7-8
259 |
260 | NN | void calls_free_2 (void *ptr)
261 | | ^~~~~~~~~~~~
262 | | |
263 | | (7) entry to 'calls_free_2'
264 | NN | {
265 | NN | free (ptr);
266 | | ~~~~~~~~~~
267 | | |
268 | | (8) second 'free' here; first 'free' was at (4)
269 |
270 { dg-end-multiline-output "" { target c++ } } */
271
272 /* The call/return to this function shouldn't appear in the path. */
273
274 void called_by_test_3 (void)
275 {
276 }
277
278 void test_3 (void *ptr)
279 {
280 free (ptr);
281 called_by_test_3 ();
282 free (ptr); /* { dg-warning "double-'free' of 'ptr'" } */
283 }
284
285 /* { dg-begin-multiline-output "" }
286 NN | free (ptr);
287 | ^~~~~~~~~~
288 'test_3': events 1-2
289 NN | free (ptr);
290 | ^~~~~~~~~~
291 | |
292 | (1) first 'free' here
293 NN | called_by_test_3 ();
294 NN | free (ptr);
295 | ~~~~~~~~~~
296 | |
297 | (2) second 'free' here; first 'free' was at (1)
298 { dg-end-multiline-output "" { target c } } */
299 /* { dg-begin-multiline-output "" }
300 NN | free (ptr);
301 | ~~~~~^~~~~
302 'void test_3(void*)': events 1-2
303 NN | free (ptr);
304 | ~~~~~^~~~~
305 | |
306 | (1) first 'free' here
307 NN | called_by_test_3 ();
308 NN | free (ptr);
309 | ~~~~~~~~~~
310 | |
311 | (2) second 'free' here; first 'free' was at (1)
312 { dg-end-multiline-output "" { target c++ } } */