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 PR21858 (fold bug)


This fixes a fold bug where we used to fold a comparison
to another, but now with incorrect types.

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

Ok for mainline?

Thanks,
Richard.


2005-06-03  Richard Guenther  <rguenth@gcc.gnu.org>

	PR middle-end/21858
	* fold-const.c (fold_binary): Fix type mismatches in folding
	of comparisons.

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

Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.590
diff -c -3 -p -r1.590 fold-const.c
*** fold-const.c	2 Jun 2005 02:57:00 -0000	1.590
--- fold-const.c	3 Jun 2005 07:46:27 -0000
*************** fold_binary (enum tree_code code, tree t
*** 9303,9314 ****
  	  switch (code)
  	    {
  	    case GE_EXPR:
! 	      arg1 = const_binop (MINUS_EXPR, arg1, integer_one_node, 0);
! 	      return fold_build2 (GT_EXPR, type, arg0, arg1);

  	    case LT_EXPR:
! 	      arg1 = const_binop (MINUS_EXPR, arg1, integer_one_node, 0);
! 	      return fold_build2 (LE_EXPR, type, arg0, arg1);

  	    default:
  	      break;
--- 9303,9318 ----
  	  switch (code)
  	    {
  	    case GE_EXPR:
! 	      arg1 = const_binop (MINUS_EXPR, arg1,
! 			          build_int_cst (TREE_TYPE (arg1), 1), 0);
! 	      return fold_build2 (GT_EXPR, type, arg0,
! 				  fold_convert (TREE_TYPE (arg0), arg1));

  	    case LT_EXPR:
! 	      arg1 = const_binop (MINUS_EXPR, arg1,
! 			          build_int_cst (TREE_TYPE (arg1), 1), 0);
! 	      return fold_build2 (LE_EXPR, type, arg0,
! 				  fold_convert (TREE_TYPE (arg0), arg1));

  	    default:
  	      break;


/* Fold used to create a GT_EXPR of pointer vs. integer types,
   which caused us to ICE in VRP.  */

/* { dg-do compile } */
/* { dg-options "-Os" } */

unsigned int dsdblm_GetBlockAddress();
void error_LocalAssert(void);
int dsdblm_CreateBlock(unsigned int address)
{
   address = dsdblm_GetBlockAddress();
   if (address >= (void*)0x00020000)
     error_LocalAssert();
   return address;
}


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