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 PR28814, ICE on valid due to wrong types in fold


This fixes an ICE in tree-vrp.c:compare_values which is because we fold
a comparison to another with mismatched types.

Bootstrapped and tested on x86_64-unknown-linux-gnu.

Ok for mainline?

Thanks,
Richard.

:ADDPATCH middle-end:

2006-08-23  Richard Guenther  <rguenther@suse.de>

	PR middle-end/28814
	* fold-const.c (fold_binary): Fold temporary to correct
	type before constructing new comparison.

	* gcc.dg/torture/pr28814.c: New testcase.


Index: fold-const.c
===================================================================
*** fold-const.c	(revision 116325)
--- fold-const.c	(working copy)
*************** fold_binary (enum tree_code code, tree t
*** 10289,10295 ****
  	  && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
  	  && 0 != (tem = const_binop (TREE_CODE (arg0) == PLUS_EXPR
  				      ? MINUS_EXPR : PLUS_EXPR,
! 				      arg1, TREE_OPERAND (arg0, 1), 0))
  	  && ! TREE_CONSTANT_OVERFLOW (tem))
  	return fold_build2 (code, type, TREE_OPERAND (arg0, 0), tem);
  
--- 10289,10296 ----
  	  && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
  	  && 0 != (tem = const_binop (TREE_CODE (arg0) == PLUS_EXPR
  				      ? MINUS_EXPR : PLUS_EXPR,
! 				      fold_convert (TREE_TYPE (arg0), arg1),
! 				      TREE_OPERAND (arg0, 1), 0))
  	  && ! TREE_CONSTANT_OVERFLOW (tem))
  	return fold_build2 (code, type, TREE_OPERAND (arg0, 0), tem);
  
Index: testsuite/gcc.dg/torture/pr28814.c
===================================================================
*** testsuite/gcc.dg/torture/pr28814.c	(revision 0)
--- testsuite/gcc.dg/torture/pr28814.c	(revision 0)
***************
*** 0 ****
--- 1,17 ----
+ /* { dg-do compile } */
+ 
+ struct w49
+ {
+   union
+   {
+   }
+   value;
+ };
+ f9887 (struct w49 a23040)
+ {
+   unsigned long r9887;
+   if (((struct structure_type24753 *) (r9887 - 1)) == ((void *) 0))
+     {
+       backtrace ("stalin.sc", 7222, 248274);
+     }
+ }


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