1 #include <stdlib.h>
2 #include "analyzer-decls.h"
3
4 extern int foo (int);
5
test(int flag,void * ptr,int * p,int n)6 int test (int flag, void *ptr, int *p, int n)
7 {
8 int result;
9 int sum = 0;
10 int i;
11
12 __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */
13
14 if (flag)
15 free (ptr);
16
17 __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
18
19 for (i = 0; i < n; i++)
20 p[i] = i;
21 for (i = 0; i < n; i++)
22 sum += foo (p[i]); /* { dg-bogus "uninitialized" } */
23 result = sum;
24
25 __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
26
27 if (flag)
28 free (ptr); /* { dg-warning "double-'free' of 'ptr'" } */
29 return result;
30 }
31
test_2(int flag,int * p,int n)32 int test_2 (int flag, int *p, int n)
33 {
34 int result;
35 int sum = 0;
36 int i;
37
38 void *ptr = malloc (16);
39
40 __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */
41
42 if (flag)
43 free (ptr);
44
45 __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
46
47 for (i = 0; i < n; i++)
48 p[i] = i;
49 for (i = 0; i < n; i++)
50 sum += foo (p[i]); /* { dg-bogus "uninitialized" } */
51 result = sum;
52
53 __analyzer_dump_exploded_nodes (0); /* { dg-warning "5 processed enodes" } */
54 // FIXME: why 5 here?
55
56 free (ptr); /* { dg-warning "double-'free' of 'ptr'" } */
57 return result;
58 }
59