| 1 |
// { dg-do compile } |
| 2 |
// { dg-options "-Wcalloc-transposed-args" } |
| 3 |
|
| 4 |
typedef __SIZE_TYPE__ size_t; |
| 5 |
extern "C" void free (void *); |
| 6 |
extern "C" void *calloc (size_t, size_t); |
| 7 |
void *myfree (void *, int, int); |
| 8 |
void *mycalloc (int, int, size_t, size_t) __attribute__((malloc, malloc (myfree), alloc_size (3, 4))); |
| 9 |
|
| 10 |
void |
| 11 |
foo (int n) |
| 12 |
{ |
| 13 |
void *p; |
| 14 |
p = __builtin_calloc (1, sizeof (int)); |
| 15 |
__builtin_free (p); |
| 16 |
p = __builtin_calloc (n, sizeof (int)); |
| 17 |
__builtin_free (p); |
| 18 |
p = __builtin_calloc (sizeof (int), 1); // { dg-warning "'\[^']*__builtin_calloc\[^']*' sizes specified with 'sizeof' in the earlier argument and not in the later argument" } |
| 19 |
__builtin_free (p); // { dg-message "earlier argument should specify number of elements, later size of each element" "" { target *-*-* } .-1 } |
| 20 |
p = __builtin_calloc (sizeof (int), n); // { dg-warning "'\[^']*__builtin_calloc\[^']*' sizes specified with 'sizeof' in the earlier argument and not in the later argument" } |
| 21 |
__builtin_free (p); // { dg-message "earlier argument should specify number of elements, later size of each element" "" { target *-*-* } .-1 } |
| 22 |
p = __builtin_calloc ((sizeof (int)), 1); // { dg-warning "'\[^']*__builtin_calloc\[^']*' sizes specified with 'sizeof' in the earlier argument and not in the later argument" } |
| 23 |
__builtin_free (p); // { dg-message "earlier argument should specify number of elements, later size of each element" "" { target *-*-* } .-1 } |
| 24 |
p = __builtin_calloc (sizeof (int) + 0, 1); |
| 25 |
__builtin_free (p); |
| 26 |
p = __builtin_calloc (sizeof (int), sizeof (char)); |
| 27 |
__builtin_free (p); |
| 28 |
p = __builtin_calloc (1 * sizeof (int), 1); |
| 29 |
__builtin_free (p); |
| 30 |
p = calloc (1, sizeof (int)); |
| 31 |
free (p); |
| 32 |
p = calloc (n, sizeof (int)); |
| 33 |
free (p); |
| 34 |
p = calloc (sizeof (int), 1); // { dg-warning "'\[^']*calloc\[^']*' sizes specified with 'sizeof' in the earlier argument and not in the later argument" } |
| 35 |
free (p); // { dg-message "earlier argument should specify number of elements, later size of each element" "" { target *-*-* } .-1 } |
| 36 |
p = calloc (sizeof (int), n); // { dg-warning "'\[^']*calloc\[^']*' sizes specified with 'sizeof' in the earlier argument and not in the later argument" } |
| 37 |
free (p); // { dg-message "earlier argument should specify number of elements, later size of each element" "" { target *-*-* } .-1 } |
| 38 |
p = calloc (sizeof (int), sizeof (char)); |
| 39 |
free (p); |
| 40 |
p = calloc (1 * sizeof (int), 1); |
| 41 |
free (p); |
| 42 |
p = mycalloc (42, 42, 1, sizeof (int)); |
| 43 |
myfree (p, 42, 42); |
| 44 |
p = mycalloc (42, 42, n, sizeof (int)); |
| 45 |
myfree (p, 42, 42); |
| 46 |
p = mycalloc (42, 42, sizeof (int), 1); // { dg-warning "'\[^']*mycalloc\[^']*' sizes specified with 'sizeof' in the earlier argument and not in the later argument" } |
| 47 |
myfree (p, 42, 42); // { dg-message "earlier argument should specify number of elements, later size of each element" "" { target *-*-* } .-1 } |
| 48 |
p = mycalloc (42, 42, sizeof (int), n); // { dg-warning "'\[^']*mycalloc\[^']*' sizes specified with 'sizeof' in the earlier argument and not in the later argument" } |
| 49 |
myfree (p, 42, 42); // { dg-message "earlier argument should specify number of elements, later size of each element" "" { target *-*-* } .-1 } |
| 50 |
p = mycalloc (42, 42, sizeof (int), sizeof (char)); |
| 51 |
myfree (p, 42, 42); |
| 52 |
p = mycalloc (42, 42, 1 * sizeof (int), 1); |
| 53 |
myfree (p, 42, 42); |
| 54 |
} |