2 #include "analyzer-decls.h"
6 static int __attribute__((noinline
))
7 do_stuff_2 (int *p
, int n
)
12 /* As malloc-vs-local.c, but hand-inlining the logic. */
14 /* Repeated (n > 10) predicate. */
16 int test_repeated_predicate_1 (int n
)
23 ptr
= (int *)malloc (sizeof (int) * n
);
27 __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
33 for (i
= 0; i
< n
; i
++)
34 p
[i
] = i
; /* { dg-warning "dereference of possibly-NULL" } */
35 for (i
= 0; i
< n
; i
++)
36 sum
+= foo (p
[i
]); /* { dg-bogus "uninitialized" } */
40 __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
43 free (ptr
); /* { dg-bogus "not on the heap" } */
45 return result
; /* { dg-bogus "leak" } */
48 /* As above, but with just one loop. */
50 int test_repeated_predicate_1a (int n
)
57 ptr
= (int *)malloc (sizeof (int) * n
);
61 __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
67 for (i
= 0; i
< n
; i
++)
68 p
[i
] = i
; /* { dg-warning "dereference of possibly-NULL" } */
72 __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
75 free (ptr
); /* { dg-bogus "not on the heap" } */
77 return result
; /* { dg-bogus "leak" } */
80 /* A simpler version of the above. */
82 int test_repeated_predicate_2 (int n
)
89 ptr
= (int *)malloc (sizeof (int) * n
);
93 __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
95 result
= do_stuff_2 (ptr
, n
);
97 __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
100 free (ptr
); /* { dg-bogus "not on the heap" } */
102 return result
; /* { dg-bogus "leak" } */
105 /* A predicate that sets a flag for the 2nd test. */
107 int test_explicit_flag (int n
)
112 int need_to_free
= 0;
116 ptr
= (int *)malloc (sizeof (int) * n
);
122 __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
128 for (i
= 0; i
< n
; i
++)
129 p
[i
] = i
; /* { dg-warning "dereference of possibly-NULL" } */
130 for (i
= 0; i
< n
; i
++)
131 sum
+= foo (p
[i
]); /* { dg-bogus "uninitialized" } */
135 __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
138 free (ptr
); /* { dg-bogus "not on the heap" } */
140 return result
; /* { dg-bogus "leak" } */
143 /* Pointer comparison. */
145 int test_pointer_comparison (int n
)
152 ptr
= (int *)malloc (sizeof (int) * n
);
156 __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
162 for (i
= 0; i
< n
; i
++)
163 p
[i
] = i
; /* { dg-warning "dereference of possibly-NULL" } */
164 for (i
= 0; i
< n
; i
++)
165 sum
+= foo (p
[i
]); /* { dg-bogus "uninitialized" } */
169 __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */
172 free (ptr
); /* { dg-bogus "not on the heap" } */
174 return result
; /* { dg-bogus "leak" } */