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



             Bug #: 55771

           Summary: Negation and type conversion incorrectly exchanged

    Classification: Unclassified

           Product: gcc

           Version: 4.8.0

            Status: UNCONFIRMED

          Keywords: wrong-code

          Severity: normal

          Priority: P3

         Component: c

        AssignedTo: unassig...@gcc.gnu.org

        ReportedBy: i...@airs.com





This program should print the same thing twice:



#include <stdio.h>

void

f1()

{

  unsigned long x = 3;

  float y = 1;

  printf ("%g\n", (-x) * y);

}

void

f2()

{

  unsigned long x = 3;

  float y = 1;

  unsigned long z = - x;

  printf ("%g\n", z * y);

}

int

main()

{

  f1();

  f2();

}



However, on x86_64 GNU/Linux with current mainline, it prints



-3

1.84467e+19



It is already incorrect in the first GIMPLE dump.  f1 has



  x = 3;

  y = 1.0e+0;

  D.2219 = (float) x;

  D.2220 = -D.2219;



f2 has



  x = 3;

  y = 1.0e+0;

  z = -x;

  D.2223 = (float) z;



In other words, in f1, the conversion to float happens before the negation.



The bug happens with both the C and C++ frontends.

Reply via email to