| 1 |
/* This bug exists in gcc-2.95, egcs-1.1.2, gcc-2.7.2 and probably |
| 2 |
every other version as well. */ |
| 3 |
|
| 4 |
void abort (void); |
| 5 |
void exit (int); |
| 6 |
|
| 7 |
typedef struct int3 { int a, b, c; } int3; |
| 8 |
|
| 9 |
int3 |
| 10 |
one (void) |
| 11 |
{ |
| 12 |
return (int3) { 1, 1, 1 }; |
| 13 |
} |
| 14 |
|
| 15 |
int3 |
| 16 |
zero (void) |
| 17 |
{ |
| 18 |
return (int3) { 0, 0, 0 }; |
| 19 |
} |
| 20 |
|
| 21 |
int |
| 22 |
main (void) |
| 23 |
{ |
| 24 |
int3 a; |
| 25 |
|
| 26 |
/* gcc allocates a temporary for the inner expression statement |
| 27 |
to store the return value of `one'. |
| 28 |
|
| 29 |
gcc frees the temporaries for the inner expression statement. |
| 30 |
|
| 31 |
gcc realloates the same temporary slot to store the return |
| 32 |
value of `zero'. |
| 33 |
|
| 34 |
gcc expands the call to zero ahead of the expansion of the |
| 35 |
statement expressions. The temporary gets the value of `zero'. |
| 36 |
|
| 37 |
gcc expands statement expressions and the stale temporary is |
| 38 |
clobbered with the value of `one'. The bad value is copied from |
| 39 |
the temporary into *&a. */ |
| 40 |
|
| 41 |
*({ ({ one (); &a; }); }) = zero (); |
| 42 |
if (a.a && a.b && a.c) |
| 43 |
abort (); |
| 44 |
exit (0); |
| 45 |
} |