| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-require-effective-target stdint_types } */ |
| 3 |
/* { dg-options "-O2 -Wvla-larger-than=40" } */ |
| 4 |
|
| 5 |
#include <stdint.h> |
| 6 |
|
| 7 |
void f0 (void *); |
| 8 |
void |
| 9 |
f1 (__SIZE_TYPE__ a) |
| 10 |
{ |
| 11 |
if (a <= 10) |
| 12 |
{ |
| 13 |
// 10 * 4 bytes = 40: OK! |
| 14 |
uint32_t x[a]; |
| 15 |
f0 (x); |
| 16 |
} |
| 17 |
} |
| 18 |
|
| 19 |
void |
| 20 |
f2 (__SIZE_TYPE__ a) |
| 21 |
{ |
| 22 |
if (a <= 11) |
| 23 |
{ |
| 24 |
// 11 * 4 bytes = 44: Not OK. |
| 25 |
uint32_t x[a]; // { dg-warning "array may be too large" } |
| 26 |
f0 (x); |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
void |
| 31 |
f3 (__SIZE_TYPE__ a, __SIZE_TYPE__ b) |
| 32 |
{ |
| 33 |
if (a <= 5 && b <= 3) |
| 34 |
{ |
| 35 |
// 5 * 3 * 4 bytes = 60: Not OK. |
| 36 |
uint32_t x[a][b]; // { dg-warning "array may be too large" } |
| 37 |
f0 (x); |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
void |
| 42 |
f4 (__SIZE_TYPE__ a, __SIZE_TYPE__ b) |
| 43 |
{ |
| 44 |
if (a <= 5 && b <= 2) |
| 45 |
{ |
| 46 |
// 5 * 2 * 4 bytes = 40 bytes: OK! |
| 47 |
uint32_t x[a][b]; |
| 48 |
f0 (x); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
void |
| 53 |
f5 (__SIZE_TYPE__ len) |
| 54 |
{ |
| 55 |
// Test that a direct call to __builtin_alloca_with_align is not |
| 56 |
// confused with a VLA. |
| 57 |
void *p = __builtin_alloca_with_align (len, 8); |
| 58 |
f0 (p); |
| 59 |
} |
| 60 |
|
| 61 |
void |
| 62 |
f6 (unsigned stuff) |
| 63 |
{ |
| 64 |
int n = 7000; |
| 65 |
do { |
| 66 |
char a[n]; // { dg-warning "variable-length array is too large" } |
| 67 |
f0 (a); |
| 68 |
} while (stuff--); |
| 69 |
} |