gcc -O2 produces bad code for function given below. Correct
code is generated for no optimization or -O.
The problem is that with -O2 the 3rd param passed to fprintf
is uninitialized garbage, not the bytes set by the assignment
More presisely, the bad code generated is:
movl %esp, %ebp
subl $12, %esp
movl stderr, %eax
movl -4(%ebp), %edx
movl $0x3fa00000, -4(%ebp)
movl %ebp, %esp
That is, %edx is set prior to the initialization of -4(%ebp).
And %edx is then passed to fprintf, causing garbage to be
The uuencoded, gzipped, preprocessed file is attached.
This error also occurs using CodeSourcery's Online Test
Compiler. The code is slightly different than what I
see using 3.0, but it is still wrong.
gcc version 3.0
Configured with: /export/gnu/gcc-3.0/configure --enable-languages=c++
Thread model: single
linux 2.4.4 running on rh7.1 (Pentium III)
fprintf(stderr, "%x\n", *(unsigned int*)&T0);
State-Changed-Why: Not a bug; your code violates ANSI C aliasing rules.
Reopening to ...
Mark as a dup of bug 21920.
*** This bug has been marked as a duplicate of 21920 ***