| 1 |
/* { dg-additional-options "-fanalyzer-transitivity" } */ |
| 2 |
/* { dg-skip-if "requires hosted libstdc++ for stdlib malloc" { ! hostedlib } } */ |
| 3 |
|
| 4 |
#include <stdlib.h> |
| 5 |
#include "analyzer-decls.h" |
| 6 |
|
| 7 |
int test_1 (int a, int b) |
| 8 |
{ |
| 9 |
void *p; |
| 10 |
|
| 11 |
if (a > 5) |
| 12 |
if (b) |
| 13 |
p = malloc (16); |
| 14 |
else |
| 15 |
p = malloc (32); |
| 16 |
|
| 17 |
__analyzer_dump_exploded_nodes (0); /* { dg-warning "3 processed enodes" } */ |
| 18 |
|
| 19 |
if (a > 5) |
| 20 |
{ |
| 21 |
free (p); |
| 22 |
__analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */ |
| 23 |
} |
| 24 |
|
| 25 |
return 0; /* { dg-bogus "leak" } */ |
| 26 |
} |
| 27 |
|
| 28 |
int test_2 (int a, int b) |
| 29 |
{ |
| 30 |
void *p; |
| 31 |
|
| 32 |
if (a > 5) |
| 33 |
if (b) |
| 34 |
p = malloc (16); |
| 35 |
else |
| 36 |
p = malloc (32); |
| 37 |
|
| 38 |
__analyzer_dump_exploded_nodes (0); /* { dg-warning "3 processed enodes" } */ |
| 39 |
|
| 40 |
if (a > 6) /* different condition */ |
| 41 |
{ |
| 42 |
free (p); |
| 43 |
__analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */ |
| 44 |
} |
| 45 |
|
| 46 |
return 0; /* { dg-warning "leak of 'p'" } */ |
| 47 |
/* leaks when a == 5. */ |
| 48 |
} |