| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-options "-O2 -std=c23" } */ |
| 3 |
|
| 4 |
|
| 5 |
/* Based on the submitted test case for PR123356 but using types with |
| 6 |
* tags and moving the second version into another scope. */ |
| 7 |
|
| 8 |
struct foo { long x; }; |
| 9 |
|
| 10 |
void f() |
| 11 |
{ |
| 12 |
struct foo { }; |
| 13 |
struct bar { struct foo *c; }; |
| 14 |
union baz { struct foo *c; }; |
| 15 |
struct arr { struct foo *c[1]; }; |
| 16 |
struct fun { struct foo (*c)(); }; |
| 17 |
} |
| 18 |
|
| 19 |
|
| 20 |
void f1() |
| 21 |
{ |
| 22 |
struct foo { }; |
| 23 |
struct bar { struct foo *c; }; |
| 24 |
union baz { struct foo *c; }; |
| 25 |
struct arr { struct foo *c[1]; }; |
| 26 |
struct fun { struct foo (*c)(); }; |
| 27 |
} |
| 28 |
|
| 29 |
struct bar { struct foo *c; }; |
| 30 |
union baz { struct foo *c; }; |
| 31 |
struct arr { struct foo *c[1]; }; |
| 32 |
struct fun { struct foo (*c)(); }; |
| 33 |
|
| 34 |
void f2() |
| 35 |
{ |
| 36 |
struct foo { int y; }; |
| 37 |
struct bar { struct foo *c; }; |
| 38 |
union baz { struct foo *c; }; |
| 39 |
struct arr { struct foo *c[1]; }; |
| 40 |
struct fun { struct foo (*c)(); }; |
| 41 |
} |
| 42 |
|
| 43 |
__attribute__((noinline)) |
| 44 |
struct foo * g1(struct bar *B, struct bar *Q) |
| 45 |
{ |
| 46 |
struct bar t = *B; |
| 47 |
*B = *Q; |
| 48 |
*Q = t; |
| 49 |
return B->c; |
| 50 |
} |
| 51 |
|
| 52 |
__attribute__((noinline)) |
| 53 |
struct foo * g2(union baz *B, union baz *Q) |
| 54 |
{ |
| 55 |
union baz t = *B; |
| 56 |
*B = *Q; |
| 57 |
*Q = t; |
| 58 |
return B->c; |
| 59 |
} |
| 60 |
|
| 61 |
__attribute__((noinline)) |
| 62 |
struct foo { long x; } * |
| 63 |
g3(struct bar { struct foo { long x; } *c; } *B, |
| 64 |
struct bar { struct foo { long x; } *c; } *Q) |
| 65 |
{ |
| 66 |
struct bar t = *B; |
| 67 |
*B = *Q; |
| 68 |
*Q = t; |
| 69 |
return B->c; |
| 70 |
} |
| 71 |
|
| 72 |
__attribute__((noinline)) |
| 73 |
struct foo * g4(struct arr *B, |
| 74 |
struct arr *Q) |
| 75 |
{ |
| 76 |
struct arr t = *B; |
| 77 |
*B = *Q; |
| 78 |
*Q = t; |
| 79 |
return B->c[0]; |
| 80 |
} |
| 81 |
|
| 82 |
__attribute__((noinline)) |
| 83 |
struct foo (*g5(struct fun *B, |
| 84 |
struct fun *Q))() |
| 85 |
{ |
| 86 |
struct fun t = *B; |
| 87 |
*B = *Q; |
| 88 |
*Q = t; |
| 89 |
return B->c; |
| 90 |
} |
| 91 |
|
| 92 |
struct foo Bd() { }; |
| 93 |
struct foo Qd() { }; |
| 94 |
|
| 95 |
int main() |
| 96 |
{ |
| 97 |
struct foo Bc = { }; |
| 98 |
struct foo Qc = { }; |
| 99 |
|
| 100 |
struct bar B = { &Bc }; |
| 101 |
struct bar Q = { &Qc }; |
| 102 |
|
| 103 |
if (g1(&B, &Q) != &Qc) |
| 104 |
__builtin_abort(); |
| 105 |
|
| 106 |
union baz Bu = { &Bc }; |
| 107 |
union baz Qu = { &Qc }; |
| 108 |
|
| 109 |
if (g2(&Bu, &Qu) != &Qc) |
| 110 |
__builtin_abort(); |
| 111 |
|
| 112 |
struct bar B2 = { &Bc }; |
| 113 |
struct bar Q2 = { &Qc }; |
| 114 |
|
| 115 |
if (g3(&B2, &Q2) != &Qc) |
| 116 |
__builtin_abort(); |
| 117 |
|
| 118 |
struct arr Ba = { &Bc }; |
| 119 |
struct arr Qa = { &Qc }; |
| 120 |
|
| 121 |
if (g4(&Ba, &Qa) != &Qc) |
| 122 |
__builtin_abort(); |
| 123 |
#if 0 |
| 124 |
// PR114959 |
| 125 |
struct fun Bf = { &Bd }; |
| 126 |
struct fun Qf = { &Qd }; |
| 127 |
|
| 128 |
if (g5(&Bf, &Qf) != &Qd) |
| 129 |
__builtin_abort(); |
| 130 |
#endif |
| 131 |
return 0; |
| 132 |
} |
| 133 |
|