[RISC-V] Avoid unnecessary extensions when value is already extended
[official-gcc.git] / gcc / testsuite / c-c++-common / analyzer / analyzer-verbosity-0.c
blobc1a3ca753e699b74ae94cc19044069af68b98d28
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 "" } */
5 #include <stdlib.h>
7 void calls_free_1 (void *ptr)
9 free (ptr); /* { dg-warning "double-'free' of 'ptr'" } */
12 void test_1 (void *ptr, int a, int b)
14 if (a)
15 calls_free_1 (ptr);
17 if (b)
20 else
21 calls_free_1 (ptr);
24 /* { dg-begin-multiline-output "" }
25 NN | free (ptr);
26 | ^~~~~~~~~~
27 'test_1': event 1
29 | NN | calls_free_1 (ptr);
30 | | ^~~~~~~~~~~~~~~~~~
31 | | |
32 | | (1) calling 'calls_free_1' from 'test_1'
34 +--> 'calls_free_1': event 2
36 | NN | free (ptr);
37 | | ^~~~~~~~~~
38 | | |
39 | | (2) first 'free' here
41 <------+
43 'test_1': events 3-4
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'
55 +--> 'calls_free_1': event 5
57 | NN | free (ptr);
58 | | ^~~~~~~~~~
59 | | |
60 | | (5) second 'free' here; first 'free' was at (2)
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
68 | NN | calls_free_1 (ptr);
69 | | ~~~~~~~~~~~~~^~~~~
70 | | |
71 | | (1) calling 'calls_free_1' from 'test_1'
73 +--> 'void calls_free_1(void*)': event 2
75 | NN | free (ptr);
76 | | ~~~~~^~~~~
77 | | |
78 | | (2) first 'free' here
80 <------+
82 'void test_1(void*, int, int)': events 3-4
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'
94 +--> 'void calls_free_1(void*)': event 5
96 | NN | free (ptr);
97 | | ~~~~~^~~~~
98 | | |
99 | | (5) second 'free' here; first 'free' was at (2)
101 { dg-end-multiline-output "" { target c++ } } */
103 void calls_free_2 (void *ptr)
105 free (ptr); /* { dg-warning "double-'free' of 'ptr'" } */
108 void test_2 (void *ptr, int a, int b)
110 switch (a)
112 default:
113 break;
114 case 1:
115 break;
116 case 3:
117 calls_free_2 (ptr);
118 break;
121 switch (b)
123 default:
124 calls_free_2 (ptr);
125 break;
126 case 1:
127 break;
128 case 42:
129 break;
133 /* { dg-begin-multiline-output "" }
134 NN | free (ptr);
135 | ^~~~~~~~~~
136 'test_2': event 1
138 | NN | calls_free_2 (ptr);
139 | | ^~~~~~~~~~~~~~~~~~
140 | | |
141 | | (1) calling 'calls_free_2' from 'test_2'
143 +--> 'calls_free_2': event 2
145 | NN | free (ptr);
146 | | ^~~~~~~~~~
147 | | |
148 | | (2) first 'free' here
150 <------+
152 'test_2': events 3-4
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'
164 +--> 'calls_free_2': event 5
166 | NN | free (ptr);
167 | | ^~~~~~~~~~
168 | | |
169 | | (5) second 'free' here; first 'free' was at (2)
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
177 | NN | calls_free_2 (ptr);
178 | | ~~~~~~~~~~~~~^~~~~
179 | | |
180 | | (1) calling 'calls_free_2' from 'test_2'
182 +--> 'void calls_free_2(void*)': event 2
184 | NN | free (ptr);
185 | | ~~~~~^~~~~
186 | | |
187 | | (2) first 'free' here
189 <------+
191 'void test_2(void*, int, int)': events 3-4
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'
203 +--> 'void calls_free_2(void*)': event 5
205 | NN | free (ptr);
206 | | ~~~~~^~~~~
207 | | |
208 | | (5) second 'free' here; first 'free' was at (2)
210 { dg-end-multiline-output "" { target c++ } } */
212 // TODO: range cases
214 /* The call/return to this function shouldn't appear in the path. */
216 void called_by_test_3 (void)
220 void test_3 (void *ptr)
222 free (ptr);
223 called_by_test_3 ();
224 free (ptr); /* { dg-warning "double-'free' of 'ptr'" } */
227 /* { dg-begin-multiline-output "" }
228 NN | free (ptr);
229 | ^~~~~~~~~~
230 'test_3': events 1-2
231 NN | free (ptr);
232 | ^~~~~~~~~~
234 | (1) first 'free' here
235 NN | called_by_test_3 ();
236 NN | free (ptr);
237 | ~~~~~~~~~~
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 | ~~~~~^~~~~
248 | (1) first 'free' here
249 NN | called_by_test_3 ();
250 NN | free (ptr);
251 | ~~~~~~~~~~
253 | (2) second 'free' here; first 'free' was at (1)
254 { dg-end-multiline-output "" { target c++ } } */