With gcc-snapshot (Debian 20091118-1) 4.5.0 20091119 (experimental) [trunk
revision 154312] on an x86_64 GNU/Linux machine and the following code (partly
based on GMP):

#include <stdio.h>

union ieee_double_extract
{
  struct
  {
    unsigned int manl:32;
    unsigned int manh:20;
    unsigned int exp:11;
    unsigned int sig:1;
  } s;
  double d;
};

int main (void)
{
  union { double d; unsigned long long i; } x;
  x.d = 0.0 / 0.0;
  printf ("d = %g [%llx]\n", x.d, x.i);
  printf ("exp = %x\n", (unsigned int)
          ((union ieee_double_extract *)&(x.d))->s.exp);
  return 0;
}

$ gcc-snapshot -Wall -Wextra testd.c -o testd
$ ./testd
d = nan [fff8000000000000]
exp = 7ff

This is OK, but with -O2:

$ gcc-snapshot -Wall -Wextra testd.c -o testd -O2
$ ./testd
d = nan [fff8000000000000]
exp = 0

I don't know whether aliasing rules are broken, but note that there are no
warnings.

GCC 4.4.2 doesn't have this problem.


-- 
           Summary: Incorrect optimization (-O2) yields wrong code
                    (regression)
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: vincent at vinc17 dot org


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

Reply via email to