This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/55771] New: Negation and type conversion incorrectly exchanged
- From: "ian at airs dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 21 Dec 2012 04:52:08 +0000
- Subject: [Bug c/55771] New: Negation and type conversion incorrectly exchanged
- Auto-submitted: auto-generated
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.