| 1 |
/* { dg-do run } |
| 2 |
* { dg-options "-std=gnu23 -O2" } |
| 3 |
*/ |
| 4 |
|
| 5 |
|
| 6 |
/* We check that the incompatible enums as fields lead to |
| 7 |
* incompatible types that can be assumed not to alias |
| 8 |
* and that this is exploited during optimization. */ |
| 9 |
|
| 10 |
struct bar1 { int x; enum A1 { X1 = 1 } f; }; |
| 11 |
|
| 12 |
[[gnu::noinline,gnu::noipa]] |
| 13 |
int test_bar1(struct bar1* a, void* b) |
| 14 |
{ |
| 15 |
a->x = 1; |
| 16 |
|
| 17 |
struct bar1 { int x; enum A1 { X1 = 2 } f; }* p = b; |
| 18 |
p->x = 2; |
| 19 |
|
| 20 |
return a->x; |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
struct bar2 { int x; enum A2 { X2 = 1 } f; }; |
| 25 |
|
| 26 |
[[gnu::noinline,gnu::noipa]] |
| 27 |
int test_bar2(struct bar2* a, void* b) |
| 28 |
{ |
| 29 |
a->x = 1; |
| 30 |
|
| 31 |
struct bar2 { int x; enum B2 { X2 = 1 } f; }* p = b; |
| 32 |
p->x = 2; |
| 33 |
|
| 34 |
return a->x; |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
struct bar3 { int x; enum A3 { X3 = 1 } f; }; |
| 40 |
|
| 41 |
[[gnu::noinline,gnu::noipa]] |
| 42 |
int test_bar3(struct bar3* a, void* b) |
| 43 |
{ |
| 44 |
a->x = 1; |
| 45 |
|
| 46 |
struct bar3 { int x; enum A3 { Y3 = 1 } f; }* p = b; |
| 47 |
p->x = 2; |
| 48 |
|
| 49 |
return a->x; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
struct bar4 { int x; enum { Z4 = 1 } f; }; |
| 54 |
|
| 55 |
[[gnu::noinline,gnu::noipa]] |
| 56 |
int test_bar4(struct bar4* a, void* b) |
| 57 |
{ |
| 58 |
a->x = 1; |
| 59 |
|
| 60 |
struct bar4 { int x; enum { Z4 = 1 } f; }* p = b; |
| 61 |
p->x = 2; |
| 62 |
|
| 63 |
return a->x; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
int main() |
| 69 |
{ |
| 70 |
struct bar1 z1; |
| 71 |
|
| 72 |
if (1 != test_bar1(&z1, &z1)) |
| 73 |
__builtin_abort(); |
| 74 |
|
| 75 |
struct bar2 z2; |
| 76 |
|
| 77 |
if (1 != test_bar2(&z2, &z2)) |
| 78 |
__builtin_abort(); |
| 79 |
|
| 80 |
struct bar3 z3; |
| 81 |
|
| 82 |
if (1 != test_bar3(&z3, &z3)) |
| 83 |
__builtin_abort(); |
| 84 |
|
| 85 |
struct bar4 z4; |
| 86 |
#if 0 |
| 87 |
// we used to test this, but this would be incorrect |
| 88 |
// if there is a declaration in another TU cf. PR117490 |
| 89 |
if (1 != test_bar4(&z4, &z4)) |
| 90 |
__builtin_abort(); |
| 91 |
#endif |
| 92 |
return 0; |
| 93 |
} |
| 94 |
|
| 95 |
|