| 1 |
/* { dg-skip-if "" { powerpc*-*-aix* } } */ |
| 2 |
/* { dg-skip-if "requires hosted libstdc++ for stdlib malloc" { ! hostedlib } } */ |
| 3 |
|
| 4 |
#include <stdlib.h> |
| 5 |
#include "../../gcc.dg/analyzer/analyzer-decls.h" |
| 6 |
|
| 7 |
typedef unsigned __INT32_TYPE__ u32; |
| 8 |
|
| 9 |
void |
| 10 |
test_1 (void) |
| 11 |
{ |
| 12 |
char buf[16]; |
| 13 |
__analyzer_dump_capacity (buf); /* { dg-warning "capacity: '\\(sizetype\\)16'" } */ |
| 14 |
} |
| 15 |
|
| 16 |
void |
| 17 |
test_2 (void) |
| 18 |
{ |
| 19 |
char ch; |
| 20 |
__analyzer_dump_capacity (&ch); /* { dg-warning "capacity: '\\(sizetype\\)1'" } */ |
| 21 |
} |
| 22 |
|
| 23 |
struct s3 { char buf[100]; }; |
| 24 |
|
| 25 |
void |
| 26 |
test_3 (void) |
| 27 |
{ |
| 28 |
struct s3 s; |
| 29 |
__analyzer_dump_capacity (&s); /* { dg-warning "capacity: '\\(sizetype\\)100'" } */ |
| 30 |
} |
| 31 |
|
| 32 |
/* Capacity refers to the base region, not any offset within it. */ |
| 33 |
|
| 34 |
void |
| 35 |
test_4 (void) |
| 36 |
{ |
| 37 |
char buf[1024]; |
| 38 |
__analyzer_dump_capacity (buf + 100); /* { dg-warning "capacity: '\\(sizetype\\)1024'" } */ |
| 39 |
} |
| 40 |
|
| 41 |
void |
| 42 |
test_5 (void *p) |
| 43 |
{ |
| 44 |
__analyzer_dump_capacity (p); /* { dg-warning "capacity: 'UNKNOWN\\(sizetype\\)'" } */ |
| 45 |
} |
| 46 |
|
| 47 |
void |
| 48 |
test_malloc (void) |
| 49 |
{ |
| 50 |
void *p = malloc (1024); |
| 51 |
|
| 52 |
__analyzer_dump_capacity (p); /* { dg-warning "capacity: '\\(size_t\\)1024'" } */ |
| 53 |
free (p); |
| 54 |
} |
| 55 |
|
| 56 |
void |
| 57 |
test_alloca (size_t sz) |
| 58 |
{ |
| 59 |
void *p = __builtin_alloca (sz); |
| 60 |
__analyzer_dump_capacity (p); /* { dg-warning "capacity: 'INIT_VAL\\(sz_\[^\n\r\]*\\)'" } */ |
| 61 |
} |
| 62 |
|
| 63 |
void |
| 64 |
test_vla (size_t sz) |
| 65 |
{ |
| 66 |
char buf[sz]; |
| 67 |
__analyzer_dump_capacity (buf); /* { dg-warning "capacity: 'INIT_VAL\\(sz_\[^\n\r\]*\\)'" } */ |
| 68 |
} |
| 69 |
|
| 70 |
static void * __attribute__((noinline)) |
| 71 |
called_by_test_interproc_malloc (size_t a) |
| 72 |
{ |
| 73 |
return malloc (a); |
| 74 |
} |
| 75 |
|
| 76 |
void * |
| 77 |
test_interproc_malloc (size_t sz) |
| 78 |
{ |
| 79 |
void *p = called_by_test_interproc_malloc (sz); |
| 80 |
__analyzer_dump_capacity (p); /* { dg-warning "capacity: 'INIT_VAL\\(sz_\[^\n\r\]*\\)'" } */ |
| 81 |
return p; |
| 82 |
} |
| 83 |
|
| 84 |
struct s |
| 85 |
{ |
| 86 |
u32 f1; |
| 87 |
char arr[]; |
| 88 |
}; |
| 89 |
|
| 90 |
static struct s * __attribute__((noinline)) |
| 91 |
alloc_s (size_t num) |
| 92 |
{ |
| 93 |
struct s *p = (struct s *) malloc (sizeof(struct s) + num); |
| 94 |
return p; |
| 95 |
} |
| 96 |
|
| 97 |
struct s * |
| 98 |
test_trailing_array (void) |
| 99 |
{ |
| 100 |
struct s *p = alloc_s (5); |
| 101 |
__analyzer_dump_capacity (p); /* { dg-warning "capacity: '\\(\[^\n\r\]*\\)9'" } */ |
| 102 |
return p; |
| 103 |
} |
| 104 |
|
| 105 |
void |
| 106 |
test_unknown_arr (int p[]) |
| 107 |
{ |
| 108 |
__analyzer_dump_capacity (p); /* { dg-warning "capacity: 'UNKNOWN\\(sizetype\\)'" } */ |
| 109 |
} |