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]

c-torture/execute/991221-1.c: un-normalizable ranges


fold_range_test() miscomputes the value of the expression:

(msize != 0 && ((msize - 1) > (2147483647L   * 2UL + 1) )

when typeof(msize) is a 32-bit unsigned long.  It ends up being
transformed in a LE expression.

The problem is that make_range computes the range as low==1 and
high==0, which is invalid.  Here's a patch that fixes this bug.  Ok to
install, assuming it doesn't introduce any regressions?  I'm currently
testing it on x86, but I'll only be able to verify the results
tomorrow.

Index: gcc/ChangeLog
from  Alexandre Oliva  <aoliva@cygnus.com>

	* fold-const.c (make_range): Handle degenerated intervals.
	Fixes c-torture/execute/991221-1.c

Index: gcc/fold-const.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/fold-const.c,v
retrieving revision 1.150
diff -u -p -c -r1.150 fold-const.c
*** gcc/fold-const.c	2000/05/15 17:46:42	1.150
--- gcc/fold-const.c	2000/05/16 17:03:38
*************** make_range (exp, pin_p, plow, phigh)
*** 3514,3521 ****
  	      low = range_binop (PLUS_EXPR, type, n_high, 0,
  				 integer_one_node, 0);
  	      high = range_binop (MINUS_EXPR, type, n_low, 0,
! 				 integer_one_node, 0);
! 	      in_p = ! in_p;
  	    }
  	  else
  	    low = n_low, high = n_high;
--- 3514,3530 ----
  	      low = range_binop (PLUS_EXPR, type, n_high, 0,
  				 integer_one_node, 0);
  	      high = range_binop (MINUS_EXPR, type, n_low, 0,
! 				  integer_one_node, 0);
! 
! 	      /* If the range is of the form +/- [ x+1, x ], we won't
! 		 be able to normalize it.  But then, it represents the
! 		 whole range or the empty set, so make it +/- [ -, - ].
! 	      */
! 	      if (tree_int_cst_equal (n_low, low)
! 		  && tree_int_cst_equal (n_high, high))
! 		low = high = 0;
! 	      else
! 		in_p = ! in_p;
  	    }
  	  else
  	    low = n_low, high = n_high;

-- 
Alexandre Oliva    Enjoy Guaranį, see http://www.ic.unicamp.br/~oliva/
Cygnus Solutions, a Red Hat company        aoliva@{redhat, cygnus}.com
Free Software Developer and Evangelist    CS PhD student at IC-Unicamp
oliva@{lsd.ic.unicamp.br, gnu.org}   Write to mailing lists, not to me

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