| 1 |
#include <stdlib.h> |
| 2 |
#include "analyzer-decls.h" |
| 3 |
|
| 4 |
/* Multiple calls to malloc (without a free) should return non-equal pointers. */ |
| 5 |
|
| 6 |
void test_1 (void) |
| 7 |
{ |
| 8 |
void *p, *q; |
| 9 |
p = malloc (1024); |
| 10 |
if (!p) |
| 11 |
return; |
| 12 |
q = malloc (1024); |
| 13 |
__analyzer_eval (p == q); /* { dg-warning "FALSE" } */ |
| 14 |
free (p); |
| 15 |
free (q); |
| 16 |
} |
| 17 |
|
| 18 |
/* Multiple calls to malloc with a free might or might not |
| 19 |
return the same pointer. */ |
| 20 |
|
| 21 |
void test_2 (void) |
| 22 |
{ |
| 23 |
void *p, *q; |
| 24 |
p = malloc (1024); |
| 25 |
if (!p) |
| 26 |
return; |
| 27 |
free (p); |
| 28 |
|
| 29 |
q = malloc (1024); |
| 30 |
__analyzer_eval (p == q); /* { dg-warning "UNKNOWN" "ideal" { xfail *-*-* } } */ |
| 31 |
/* { dg-bogus "FALSE" "status quo" { xfail *-*-* } .-1 } */ |
| 32 |
// TODO: ideally this should be UNKNOWN |
| 33 |
free (q); |
| 34 |
} |
| 35 |
|
| 36 |
void test_two_malloc_sites_same_size (int flag) |
| 37 |
{ |
| 38 |
void *p; |
| 39 |
if (flag) |
| 40 |
p = malloc (1024); |
| 41 |
else |
| 42 |
p = malloc (1024); |
| 43 |
__analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */ |
| 44 |
free (p); |
| 45 |
} |
| 46 |
|
| 47 |
void test_two_malloc_sites_different_sizes (int flag) |
| 48 |
{ |
| 49 |
void *p; |
| 50 |
if (flag) |
| 51 |
p = malloc (4096); |
| 52 |
else |
| 53 |
p = malloc (1024); |
| 54 |
__analyzer_dump_exploded_nodes (0); /* { dg-warning "2 processed enodes" } */ |
| 55 |
free (p); |
| 56 |
} |