Debian Codegraph @

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

raw
1 /* { dg-additional-options "-fdiagnostics-show-line-numbers -fdiagnostics-path-format=inline-events -fdiagnostics-show-caret -fanalyzer-verbosity=0" } */
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': event 1
28 |
29 | NN | calls_free_1 (ptr);
30 | | ^~~~~~~~~~~~~~~~~~
31 | | |
32 | | (1) calling 'calls_free_1' from 'test_1'
33 |
34 +--> 'calls_free_1': event 2
35 |
36 | NN | free (ptr);
37 | | ^~~~~~~~~~
38 | | |
39 | | (2) first 'free' here
40 |
41 <------+
42 |
43 'test_1': events 3-4
44 |
45 | NN | calls_free_1 (ptr);
46 | | ^~~~~~~~~~~~~~~~~~
47 | | |
48 | | (3) returning to 'test_1' from 'calls_free_1'
49 |......
50 | NN | calls_free_1 (ptr);
51 | | ~~~~~~~~~~~~~~~~~~
52 | | |
53 | | (4) passing freed pointer 'ptr' in call to 'calls_free_1' from 'test_1'
54 |
55 +--> 'calls_free_1': event 5
56 |
57 | NN | free (ptr);
58 | | ^~~~~~~~~~
59 | | |
60 | | (5) second 'free' here; first 'free' was at (2)
61 |
62 { dg-end-multiline-output "" { target c } } */
63 /* { dg-begin-multiline-output "" }
64 NN | free (ptr);
65 | ~~~~~^~~~~
66 'void test_1(void*, int, int)': event 1
67 |
68 | NN | calls_free_1 (ptr);
69 | | ~~~~~~~~~~~~~^~~~~
70 | | |
71 | | (1) calling 'calls_free_1' from 'test_1'
72 |
73 +--> 'void calls_free_1(void*)': event 2
74 |
75 | NN | free (ptr);
76 | | ~~~~~^~~~~
77 | | |
78 | | (2) first 'free' here
79 |
80 <------+
81 |
82 'void test_1(void*, int, int)': events 3-4
83 |
84 | NN | calls_free_1 (ptr);
85 | | ~~~~~~~~~~~~~^~~~~
86 | | |
87 | | (3) returning to 'test_1' from 'calls_free_1'
88 |......
89 | NN | calls_free_1 (ptr);
90 | | ~~~~~~~~~~~~~~~~~~
91 | | |
92 | | (4) passing freed pointer 'ptr' in call to 'calls_free_1' from 'test_1'
93 |
94 +--> 'void calls_free_1(void*)': event 5
95 |
96 | NN | free (ptr);
97 | | ~~~~~^~~~~
98 | | |
99 | | (5) second 'free' here; first 'free' was at (2)
100 |
101 { dg-end-multiline-output "" { target c++ } } */
102
103 void calls_free_2 (void *ptr)
104 {
105 free (ptr); /* { dg-warning "double-'free' of 'ptr'" } */
106 }
107
108 void test_2 (void *ptr, int a, int b)
109 {
110 switch (a)
111 {
112 default:
113 break;
114 case 1:
115 break;
116 case 3:
117 calls_free_2 (ptr);
118 break;
119 }
120
121 switch (b)
122 {
123 default:
124 calls_free_2 (ptr);
125 break;
126 case 1:
127 break;
128 case 42:
129 break;
130 }
131 }
132
133 /* { dg-begin-multiline-output "" }
134 NN | free (ptr);
135 | ^~~~~~~~~~
136 'test_2': event 1
137 |
138 | NN | calls_free_2 (ptr);
139 | | ^~~~~~~~~~~~~~~~~~
140 | | |
141 | | (1) calling 'calls_free_2' from 'test_2'
142 |
143 +--> 'calls_free_2': event 2
144 |
145 | NN | free (ptr);
146 | | ^~~~~~~~~~
147 | | |
148 | | (2) first 'free' here
149 |
150 <------+
151 |
152 'test_2': events 3-4
153 |
154 | NN | calls_free_2 (ptr);
155 | | ^~~~~~~~~~~~~~~~~~
156 | | |
157 | | (3) returning to 'test_2' from 'calls_free_2'
158 |......
159 | NN | calls_free_2 (ptr);
160 | | ~~~~~~~~~~~~~~~~~~
161 | | |
162 | | (4) passing freed pointer 'ptr' in call to 'calls_free_2' from 'test_2'
163 |
164 +--> 'calls_free_2': event 5
165 |
166 | NN | free (ptr);
167 | | ^~~~~~~~~~
168 | | |
169 | | (5) second 'free' here; first 'free' was at (2)
170 |
171 { dg-end-multiline-output "" { target c } } */
172 /* { dg-begin-multiline-output "" }
173 NN | free (ptr);
174 | ~~~~~^~~~~
175 'void test_2(void*, int, int)': event 1
176 |
177 | NN | calls_free_2 (ptr);
178 | | ~~~~~~~~~~~~~^~~~~
179 | | |
180 | | (1) calling 'calls_free_2' from 'test_2'
181 |
182 +--> 'void calls_free_2(void*)': event 2
183 |
184 | NN | free (ptr);
185 | | ~~~~~^~~~~
186 | | |
187 | | (2) first 'free' here
188 |
189 <------+
190 |
191 'void test_2(void*, int, int)': events 3-4
192 |
193 | NN | calls_free_2 (ptr);
194 | | ~~~~~~~~~~~~~^~~~~
195 | | |
196 | | (3) returning to 'test_2' from 'calls_free_2'
197 |......
198 | NN | calls_free_2 (ptr);
199 | | ~~~~~~~~~~~~~~~~~~
200 | | |
201 | | (4) passing freed pointer 'ptr' in call to 'calls_free_2' from 'test_2'
202 |
203 +--> 'void calls_free_2(void*)': event 5
204 |
205 | NN | free (ptr);
206 | | ~~~~~^~~~~
207 | | |
208 | | (5) second 'free' here; first 'free' was at (2)
209 |
210 { dg-end-multiline-output "" { target c++ } } */
211
212 // TODO: range cases
213
214 /* The call/return to this function shouldn't appear in the path. */
215
216 void called_by_test_3 (void)
217 {
218 }
219
220 void test_3 (void *ptr)
221 {
222 free (ptr);
223 called_by_test_3 ();
224 free (ptr); /* { dg-warning "double-'free' of 'ptr'" } */
225 }
226
227 /* { dg-begin-multiline-output "" }
228 NN | free (ptr);
229 | ^~~~~~~~~~
230 'test_3': events 1-2
231 NN | free (ptr);
232 | ^~~~~~~~~~
233 | |
234 | (1) first 'free' here
235 NN | called_by_test_3 ();
236 NN | free (ptr);
237 | ~~~~~~~~~~
238 | |
239 | (2) second 'free' here; first 'free' was at (1)
240 { dg-end-multiline-output "" { target c } } */
241 /* { dg-begin-multiline-output "" }
242 NN | free (ptr);
243 | ~~~~~^~~~~
244 'void test_3(void*)': events 1-2
245 NN | free (ptr);
246 | ~~~~~^~~~~
247 | |
248 | (1) first 'free' here
249 NN | called_by_test_3 ();
250 NN | free (ptr);
251 | ~~~~~~~~~~
252 | |
253 | (2) second 'free' here; first 'free' was at (1)
254 { dg-end-multiline-output "" { target c++ } } */