Bug 4069 - gcc -O2 produces bad code using gcc 3.0 on i686-pc-linux-gnu
gcc -O2 produces bad code using gcc 3.0 on i686-pc-linux-gnu
Status: RESOLVED DUPLICATE of bug 21920
Product: gcc
Classification: Unclassified
Component: rtl-optimization
3.0
: P3 normal
: ---
Assigned To: Not yet assigned to anyone
: wrong-code
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2001-08-21 07:46 UTC by pjh
Modified: 2005-06-05 09:31 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
b.i.gz.uu (5.19 KB, application/octet-stream)
2003-05-21 15:17 UTC, pjh
Details

Note You need to log in before you can comment on or make changes to this bug.
Description pjh 2001-08-21 07:46:01 UTC
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
to T0.

More presisely, the bad code generated is:
main:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $12, %esp
        movl    stderr, %eax
        movl    -4(%ebp), %edx
        movl    $0x3fa00000, -4(%ebp)
        pushl   %edx
        pushl   $.LC0
        pushl   %eax
        call    fprintf
        movl    %ebp, %esp
        popl    %ebp
        ret

That is, %edx is set prior to the initialization of -4(%ebp).
And %edx is then passed to fprintf, causing garbage to be
printed.

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.

Release:
gcc version 3.0

Environment:
i686-pc-linux-gnu

Configured with: /export/gnu/gcc-3.0/configure --enable-languages=c++
Thread model: single

linux 2.4.4 running on rh7.1 (Pentium III)

How-To-Repeat:
#include <stdio.h>

main()
{
  float T0;
  T0=1.25;
  fprintf(stderr, "%x\n", *(unsigned int*)&T0);
}
Comment 1 Neil Booth 2001-08-21 08:11:30 UTC
State-Changed-From-To: open->closed
State-Changed-Why: Not a bug; your code violates ANSI C aliasing rules.
Comment 2 Andrew Pinski 2005-06-05 09:31:28 UTC
Reopening to ...
Comment 3 Andrew Pinski 2005-06-05 09:31:49 UTC
Mark as a dup of bug 21920.

*** This bug has been marked as a duplicate of 21920 ***