This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/57886] New: Invalid folding of (float)-x to -(float)x
- From: "matz at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 12 Jul 2013 13:02:57 +0000
- Subject: [Bug middle-end/57886] New: Invalid folding of (float)-x to -(float)x
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57886
Bug ID: 57886
Summary: Invalid folding of (float)-x to -(float)x
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: matz at gcc dot gnu.org
Came up in IRC, GCC invalidly moves a conversion innerwards:
% cat x.c
extern void abort (void);
float global;
int main()
{
unsigned long z = 1;
float x = -z;
global = x;
if (global < 0)
abort ();
return 0;
}
% gcc x.c && ./a.out
Aborted
This is because GCC transforms the initializer of x (float)-z, into
-(float)z, even though z is an unsigned int. -z is always positive, but
due to this x will be -1.