| 1 |
/* { dg-do run } |
| 2 |
* { dg-options "-std=gnu23 -O2" } |
| 3 |
*/ |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
/* Here we check that struct with a variable size (GNU extension) |
| 8 |
* can alias a struct with a flexible array member or a struct with a |
| 9 |
* fixed size array as last element. */ |
| 10 |
|
| 11 |
struct bar { int x; int f[]; }; |
| 12 |
|
| 13 |
[[gnu::noinline,gnu::noipa]] |
| 14 |
int test_bar4(struct bar* a, void* b) |
| 15 |
{ |
| 16 |
a->x = 1; |
| 17 |
|
| 18 |
int n = 3; |
| 19 |
struct bar { int x; int f[n]; }* p = b; |
| 20 |
struct bar* q = a; |
| 21 |
p->x = 2; |
| 22 |
|
| 23 |
return a->x; |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
struct foo { int x; int f[3]; }; |
| 28 |
|
| 29 |
|
| 30 |
[[gnu::noinline,gnu::noipa]] |
| 31 |
int test_foo1(struct foo* a, void* b) |
| 32 |
{ |
| 33 |
a->x = 1; |
| 34 |
|
| 35 |
int n = 3; |
| 36 |
struct foo { int x; int f[n]; }* p = b; |
| 37 |
struct foo* q = a; |
| 38 |
p->x = 2; |
| 39 |
|
| 40 |
return a->x; |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
int main() |
| 46 |
{ |
| 47 |
struct bar z; |
| 48 |
|
| 49 |
if (2 != test_bar4(&z, &z)) |
| 50 |
__builtin_abort(); |
| 51 |
|
| 52 |
struct foo y; |
| 53 |
|
| 54 |
if (2 != test_foo1(&y, &y)) |
| 55 |
__builtin_abort(); |
| 56 |
|
| 57 |
return 0; |
| 58 |
} |
| 59 |
|
| 60 |
|