| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-Walloca-larger-than=2000 -O2" } */ |
| 3 |
|
| 4 |
void f (void *); |
| 5 |
|
| 6 |
__SIZE_TYPE__ LIMIT; |
| 7 |
|
| 8 |
// Warn when there is an alloca bound, but it is an unknown bound. |
| 9 |
|
| 10 |
void |
| 11 |
g1 (__SIZE_TYPE__ n) |
| 12 |
{ |
| 13 |
void *p; |
| 14 |
if (n < LIMIT) |
| 15 |
p = __builtin_alloca (n); // { dg-warning "may be too large" } |
| 16 |
else |
| 17 |
p = __builtin_malloc (n); |
| 18 |
f (p); |
| 19 |
} |
| 20 |
|
| 21 |
// Similar to the above, but do not get confused by the upcast. |
| 22 |
|
| 23 |
unsigned short SHORT_LIMIT; |
| 24 |
void |
| 25 |
g2 (unsigned short n) |
| 26 |
{ |
| 27 |
void *p; |
| 28 |
if (n < SHORT_LIMIT) |
| 29 |
p = __builtin_alloca (n); // { dg-warning "may be too large" } |
| 30 |
else |
| 31 |
p = __builtin_malloc (n); |
| 32 |
f (p); |
| 33 |
} |