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.