| 1 |
/* { dg-do run } |
| 2 |
* { dg-options "-std=gnu23 -O2" } |
| 3 |
*/ |
| 4 |
|
| 5 |
|
| 6 |
/* These tests check that incompatible definitions of |
| 7 |
tagged types can be assumed not to alias and that |
| 8 |
this is exploited during optimization. */ |
| 9 |
|
| 10 |
struct foo { int x; }; |
| 11 |
|
| 12 |
[[gnu::noinline,gnu::noipa]] |
| 13 |
int test_foo1(struct foo* a, void* b) |
| 14 |
{ |
| 15 |
a->x = 1; |
| 16 |
|
| 17 |
struct foo { int x; int y; }* p = b; |
| 18 |
p->x = 2; |
| 19 |
|
| 20 |
return a->x; |
| 21 |
} |
| 22 |
|
| 23 |
[[gnu::noinline,gnu::noipa]] |
| 24 |
int test_foo2(struct foo* a, void* b) |
| 25 |
{ |
| 26 |
a->x = 1; |
| 27 |
|
| 28 |
struct fox { int x; }* p = b; |
| 29 |
p->x = 2; |
| 30 |
|
| 31 |
return a->x; |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
/* While these tests check that incompatible enums can still |
| 37 |
* alias, although this is not required. */ |
| 38 |
|
| 39 |
enum bar { A = 1, B = 3, C = 5, D = 9 }; |
| 40 |
|
| 41 |
[[gnu::noinline,gnu::noipa]] |
| 42 |
int test_bar1(enum bar* a, void* b) |
| 43 |
{ |
| 44 |
*a = A; |
| 45 |
|
| 46 |
enum bar { A = 1, B = 3, C = 6, D = 9 }* p = b; |
| 47 |
*p = B; |
| 48 |
|
| 49 |
return *a; |
| 50 |
} |
| 51 |
|
| 52 |
[[gnu::noinline,gnu::noipa]] |
| 53 |
int test_bar2(enum bar* a, void* b) |
| 54 |
{ |
| 55 |
*a = A; |
| 56 |
|
| 57 |
enum baX { A = 1, B = 3, C = 5, D = 9 }* p = b; |
| 58 |
*p = B; |
| 59 |
|
| 60 |
return *a; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
int main() |
| 65 |
{ |
| 66 |
struct foo y; |
| 67 |
|
| 68 |
if (1 != test_foo1(&y, &y)) |
| 69 |
__builtin_abort(); |
| 70 |
|
| 71 |
if (1 != test_foo2(&y, &y)) |
| 72 |
__builtin_abort(); |
| 73 |
|
| 74 |
enum bar z; |
| 75 |
|
| 76 |
if (B != test_bar1(&z, &z)) |
| 77 |
__builtin_abort(); |
| 78 |
|
| 79 |
if (B != test_bar2(&z, &z)) |
| 80 |
__builtin_abort(); |
| 81 |
|
| 82 |
return 0; |
| 83 |
} |
| 84 |
|
| 85 |
|