From: Richard Guenther Date: Sun, 31 Aug 2008 13:39:26 +0000 (+0000) Subject: re PR middle-end/37289 (ICE after non-trivial conversion at assignment) X-Git-Tag: releases/gcc-4.4.0~2746 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2b2587f577ebc08d489132307517f5bb9fb35346;p=thirdparty%2Fgcc.git re PR middle-end/37289 (ICE after non-trivial conversion at assignment) 2008-08-31 Richard Guenther PR middle-end/37289 * fold-const.c (fold_binary): Retain conversions in folding ~A + 1 to -A. * gcc.dg/pr37289.c: New testcase. From-SVN: r139831 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b20e8b23769f..72a46cfefab6 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2008-08-31 Richard Guenther + + PR middle-end/37289 + * fold-const.c (fold_binary): Retain conversions in folding + ~A + 1 to -A. + 2008-08-31 Jan Hubicka * postreload-gcse.c (eliminate_partially_redundant_loads): Use optimize_bb_for_size_p. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index ae66ad4ee2da..561fb809314b 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -9498,7 +9498,8 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) /* Convert ~A + 1 to -A. */ if (TREE_CODE (arg0) == BIT_NOT_EXPR && integer_onep (arg1)) - return fold_build1 (NEGATE_EXPR, type, TREE_OPERAND (arg0, 0)); + return fold_build1 (NEGATE_EXPR, type, + fold_convert (type, TREE_OPERAND (arg0, 0))); /* ~X + X is -1. */ if (TREE_CODE (arg0) == BIT_NOT_EXPR diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c03514ceee01..153c538fc9ce 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-08-31 Richard Guenther + + PR middle-end/37289 + * gcc.dg/pr37289.c: New testcase. + 2008-08-31 Jakub Jelinek PR target/37168 diff --git a/gcc/testsuite/gcc.dg/pr37289.c b/gcc/testsuite/gcc.dg/pr37289.c new file mode 100644 index 000000000000..61513c94ee26 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr37289.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-original" } */ + +void f(unsigned long x); + +void g(long x) +{ + f((unsigned long)(-1-x)+1); +} + +/* Make sure we do not lose the conversion. */ + +/* { dg-final { scan-tree-dump "-\\\(long unsigned int\\\) x" "original" } } */ +/* { dg-final { cleanup-tree-dump "original" } } */