public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/17865] New: Bad code generation (using -O2 and -O3) on x86 target when using the listed snippet
@ 2004-10-06 18:12 davidel at xmailserver dot org
  2004-10-06 18:12 ` [Bug c/17865] " davidel at xmailserver dot org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: davidel at xmailserver dot org @ 2004-10-06 18:12 UTC (permalink / raw)
  To: gcc-bugs

When compiling the simple program below using -O1 and -O{2,3}, you will get
different results.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define __HI(x) ((int *) &(x))[1]

double test(double v) {
        int hi;
        hi = __HI(v);
        return hi + v;
}

int main(int ac, char **av) {
        double v = 2.30912;
        if (ac > 1)
                v = atof(av[1]);
        printf("val=%lf\n", test(v));
        return 0;
}


Looking at the code generation you will notice that the offset of the "fildl" is
clearly wrong, being it accessing the uninitialized part of the stack (it should
have been "12(%ebp)"):

test:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $8, %esp
        fildl   -4(%ebp)
        faddl   8(%ebp)
        leave
        ret

-- 
           Summary: Bad code generation (using -O2 and -O3) on x86 target
                    when using the listed snippet
           Product: gcc
           Version: 3.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: davidel at xmailserver dot org
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: 3.3.2
GCC target triplet: 3.3.2


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17865


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2005-06-05  9:00 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-06 18:12 [Bug c/17865] New: Bad code generation (using -O2 and -O3) on x86 target when using the listed snippet davidel at xmailserver dot org
2004-10-06 18:12 ` [Bug c/17865] " davidel at xmailserver dot org
2004-10-06 18:13 ` davidel at xmailserver dot org
2004-10-06 18:13 ` davidel at xmailserver dot org
2004-10-06 18:20 ` pinskia at gcc dot gnu dot org
2004-10-06 18:30 ` davidel at xmailserver dot org
2004-10-06 18:34 ` pinskia at gcc dot gnu dot org
2004-10-06 18:41 ` bangerth at dealii dot org
2004-10-06 18:50 ` davidel at xmailserver dot org
2004-10-06 19:00 ` pinskia at gcc dot gnu dot org
2004-10-06 19:03 ` bangerth at dealii dot org
2005-06-05  8:59 ` pinskia at gcc dot gnu dot org
2005-06-05  9:01 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).