[backport gcc-4.9/trunk r200926 ] gcc/ 2013-07-12 Michael Matz PR middle-end/55771 * convert.c (convert_to_real): Reject non-float inner types. gcc/testsuite/ 2013-07-12 Michael Matz PR middle-end/55771 * c-c++-common/pr55771.c: New test. --- gcc-4.7.3/gcc/convert.c.~1~ 2012-04-27 12:51:58.000000000 +0200 +++ gcc-4.7.3/gcc/convert.c 2013-07-13 09:06:12.994308969 +0200 @@ -261,11 +261,12 @@ convert_to_real (tree type, tree expr) switch (TREE_CODE (expr)) { /* Convert (float)-x into -(float)x. This is safe for - round-to-nearest rounding mode. */ + round-to-nearest rounding mode when the inner type is float. */ case ABS_EXPR: case NEGATE_EXPR: if (!flag_rounding_math - && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (expr))) + && FLOAT_TYPE_P (itype) + && TYPE_PRECISION (type) < TYPE_PRECISION (itype)) return build1 (TREE_CODE (expr), type, fold (convert_to_real (type, TREE_OPERAND (expr, 0)))); --- gcc-4.7.3/gcc/testsuite/c-c++-common/pr55771.c.~1~ 1970-01-01 01:00:00.000000000 +0100 +++ gcc-4.7.3/gcc/testsuite/c-c++-common/pr55771.c 2013-07-13 09:06:12.994308969 +0200 @@ -0,0 +1,12 @@ +/* { dg-do run } */ + +float global; +int main() +{ + unsigned long z = 1; + float x = -z; + global = x; + if (global < 0) + __builtin_abort (); + return 0; +}