public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/55771] New: Negation and type conversion incorrectly exchanged
@ 2012-12-21  4:52 ian at airs dot com
  2012-12-21  5:27 ` [Bug c/55771] " ppluzhnikov at google dot com
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: ian at airs dot com @ 2012-12-21  4:52 UTC (permalink / raw)
  To: gcc-bugs


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: unassigned@gcc.gnu.org
        ReportedBy: ian@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.


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

end of thread, other threads:[~2021-08-18 21:53 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-21  4:52 [Bug c/55771] New: Negation and type conversion incorrectly exchanged ian at airs dot com
2012-12-21  5:27 ` [Bug c/55771] " ppluzhnikov at google dot com
2012-12-21  6:59 ` xinliangli at gmail dot com
2012-12-21  9:00 ` mikpe at it dot uu.se
2012-12-21 10:07 ` mikpe at it dot uu.se
2012-12-21 10:10 ` rguenth at gcc dot gnu.org
2012-12-21 13:29 ` ian at airs dot com
2012-12-21 13:53 ` [Bug middle-end/55771] " rguenth at gcc dot gnu.org
2012-12-21 13:56 ` rguenth at gcc dot gnu.org
2012-12-21 13:58 ` rguenth at gcc dot gnu.org
2012-12-21 13:59 ` jakub at gcc dot gnu.org
2012-12-21 14:09 ` jakub at gcc dot gnu.org
2013-07-12 13:23 ` matz at gcc dot gnu.org
2021-08-18 21:53 ` pinskia at gcc dot gnu.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).