This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix PR37289, wrong types from fold


Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to the trunk.

Richard.

2008-08-31  Richard Guenther  <rguenther@suse.de>

	PR middle-end/37289
	* fold-const.c (fold_binary): Retain conversions in folding
	~A + 1 to -A.

	* gcc.dg/pr37289.c: New testcase.

Index: gcc/fold-const.c
===================================================================
*** gcc/fold-const.c	(revision 139823)
--- gcc/fold-const.c	(working copy)
*************** fold_binary (enum tree_code code, tree t
*** 9498,9504 ****
  	  /* 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));
  
  	  /* ~X + X is -1.  */
  	  if (TREE_CODE (arg0) == BIT_NOT_EXPR
--- 9498,9505 ----
  	  /* Convert ~A + 1 to -A.  */
  	  if (TREE_CODE (arg0) == BIT_NOT_EXPR
  	      && integer_onep (arg1))
! 	    return fold_build1 (NEGATE_EXPR, type,
! 				fold_convert (type, TREE_OPERAND (arg0, 0)));
  
  	  /* ~X + X is -1.  */
  	  if (TREE_CODE (arg0) == BIT_NOT_EXPR
Index: gcc/testsuite/gcc.dg/pr37289.c
===================================================================
*** gcc/testsuite/gcc.dg/pr37289.c	(revision 0)
--- gcc/testsuite/gcc.dg/pr37289.c	(revision 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" } } */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]