| 1 |
/* test the combination of attribute strict_flex_array and option |
| 2 |
-fstrict-flex-arrays: when both attribute and option specified, |
| 3 |
attribute will have higher priority. */ |
| 4 |
/* { dg-do run } */ |
| 5 |
/* { dg-options "-O2 -fstrict-flex-arrays=3" } */ |
| 6 |
|
| 7 |
#include <stdio.h> |
| 8 |
|
| 9 |
#define expect(p, _v) do { \ |
| 10 |
size_t v = _v; \ |
| 11 |
if (p == v) \ |
| 12 |
printf("ok: %s == %zd\n", #p, p); \ |
| 13 |
else \ |
| 14 |
{ \ |
| 15 |
printf("WAT: %s == %zd (expected %zd)\n", #p, p, v); \ |
| 16 |
__builtin_abort (); \ |
| 17 |
} \ |
| 18 |
} while (0); |
| 19 |
|
| 20 |
struct trailing_array_1 { |
| 21 |
int a; |
| 22 |
int b; |
| 23 |
int c[4] __attribute__ ((strict_flex_array (0))); |
| 24 |
}; |
| 25 |
|
| 26 |
struct trailing_array_2 { |
| 27 |
int a; |
| 28 |
int b; |
| 29 |
int c[1] __attribute__ ((strict_flex_array (1))); |
| 30 |
}; |
| 31 |
|
| 32 |
struct trailing_array_3 { |
| 33 |
int a; |
| 34 |
int b; |
| 35 |
int c[0] __attribute__ ((strict_flex_array (2))); |
| 36 |
}; |
| 37 |
struct trailing_array_4 { |
| 38 |
int a; |
| 39 |
int b; |
| 40 |
int c[]; |
| 41 |
}; |
| 42 |
|
| 43 |
void __attribute__((__noinline__)) stuff( |
| 44 |
struct trailing_array_1 *normal, |
| 45 |
struct trailing_array_2 *trailing_1, |
| 46 |
struct trailing_array_3 *trailing_0, |
| 47 |
struct trailing_array_4 *trailing_flex) |
| 48 |
{ |
| 49 |
expect(__builtin_object_size(normal->c, 1), -1); |
| 50 |
expect(__builtin_object_size(trailing_1->c, 1), -1); |
| 51 |
expect(__builtin_object_size(trailing_0->c, 1), -1); |
| 52 |
expect(__builtin_object_size(trailing_flex->c, 1), -1); |
| 53 |
} |
| 54 |
|
| 55 |
int main(int argc, char *argv[]) |
| 56 |
{ |
| 57 |
stuff((void *)argv[0], (void *)argv[0], (void *)argv[0], (void *)argv[0]); |
| 58 |
|
| 59 |
return 0; |
| 60 |
} |