| 1 |
/* { dg-do compile } |
| 2 |
* { dg-options "-std=c23 -O2" } |
| 3 |
*/ |
| 4 |
|
| 5 |
/* The structs are incompatible so can be assumed not to |
| 6 |
* alias, but this is not exploited. So do not check for |
| 7 |
* this below but check the error about incompatibility. */ |
| 8 |
|
| 9 |
struct bar { int x; int f[]; }; |
| 10 |
|
| 11 |
int test_bar3(struct bar* a, void* b) |
| 12 |
{ |
| 13 |
a->x = 1; |
| 14 |
|
| 15 |
struct bar { int x; int f[1]; }* p = b; |
| 16 |
struct bar* q = a; /* { dg-error "incompatible" } */ |
| 17 |
p->x = 2; |
| 18 |
|
| 19 |
return a->x; |
| 20 |
} |
| 21 |
|
| 22 |
|
| 23 |
int main() |
| 24 |
{ |
| 25 |
struct bar z; |
| 26 |
|
| 27 |
// allow both results here |
| 28 |
int r = test_bar3(&z, &z); |
| 29 |
|
| 30 |
// UB but could be expected to return 1 with optimization |
| 31 |
// exploiting the UB (not done at time of writing) or 2 |
| 32 |
|
| 33 |
return r; |
| 34 |
} |
| 35 |
|
| 36 |
|