Strange bug in egcs-1.1.2 suspected
Jeffrey A Law
law@cygnus.com
Wed Jun 30 15:43:00 GMT 1999
In message < 37665FF4.F7203D26@darmstadt.gmd.de >you write:
> -------------------------------------------------------------
> #include <stdio.h>
>
> int
> main(int argc, char **argv)
> {
> struct {char c1, c2, c3, c4;} t;
> t.c4 = 0x78; t.c3 = 0x56; t.c2 = 0x34; t.c1 = 0x12;
> printf("0x%x\n", *((unsigned long*) &t));
> return 0;
> }
> -------------------------------------------------------------
> Remember, the following is compiled with egcs-1.1.2 where Mark's
> aliasing framework is disabled by default:
>
> pommnitz ~/alias>gcc aliasorig.c -o aliasorig
> pommnitz ~/alias>./aliasorig
> 0x78563412
> pommnitz ~/alias>gcc -O2 aliasorig.c -o aliasorig
> pommnitz ~/alias>./aliasorig
> 0x12
> pommnitz ~/alias>gcc -O2 -fno-strict-aliasing aliasorig.c -o aliasorig
> pommnitz ~/alias>./aliasorig
> 0x12
This is a known bug in egcs-1.1.2 -- it is not related to strict aliasing.
Though the code is not valid according to the aliasing rules of ISO/ANSI.
> #include <stdio.h>
>
> #define noalias(type, ptr) (((union { type __x__; __typeof__(*(ptr)) __y__;
> } *)(ptr))->__x__)
>
> int
> main(int argc, char **argv)
> {
> struct {char c1, c2, c3, c4;} t;
> t.c4 = 0x78; t.c3 = 0x56; t.c2 = 0x34; t.c1 = 0x12;
> printf("0x%x\n", noalias (unsigned long, &t));
> return 0;
> }
> -------------------------------------------------------------
>
> The result:
> pommnitz ~/alias>gcc -O2 alias2.c -o alias2
> pommnitz ~/alias>./alias2
> 0x12
>
> Still not what we want. OK, next try:
No surprise since the bug in egcs-1.1.2 isn't related to type based aliasing.
> Can somebody comment on this?
Yea, there was a code gen bug in egcs-1.1.2 independent of strict aliasing
that caused this code to blow up. That bug has been fixed. All three
versions produce the correct answers with gcc-2.95, even though correctness
for the first one can not be guaranteed due to strict aliasing violations.
jeff
More information about the Gcc
mailing list