Somewhat-related changes to expr.c & tree.c

Richard Henderson rth@redhat.com
Sun Nov 19 12:13:00 GMT 2000


On Sun, Nov 19, 2000 at 03:00:25PM -0500, Richard Kenner wrote:
> Hmmm.  I have no good suggestions here.  In C, sizetype is unsigned, but
> the upper bound is -1, which overflows.
> 
> This clearly needs more thought.

Well, build_range_type suggests that open-ended ranges are possible,
and layout_type considers such arrays to have zero size (or perhaps
rather declines to compute a size?).

The following also passes the two test cases.



r~



Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-decl.c,v
retrieving revision 1.179
diff -c -p -d -r1.179 c-decl.c
*** c-decl.c	2000/11/19 08:36:18	1.179
--- c-decl.c	2000/11/19 20:12:31
*************** grokdeclarator (declarator, declspecs, d
*** 4498,4506 ****
  		{
  		  /* A zero-length array cannot be represented with an
  		     unsigned index type, which is what we'll get with
! 		     build_index_type.  Create a signed range instead.  */
! 		  itype = build_range_type (index_type, size,
! 					    build_int_2 (-1, -1));
  		}
  	      else
  		{
--- 4498,4505 ----
  		{
  		  /* A zero-length array cannot be represented with an
  		     unsigned index type, which is what we'll get with
! 		     build_index_type.  Create an open-ended range instead.  */
! 		  itype = build_range_type (sizetype, size, NULL_TREE);
  		}
  	      else
  		{
Index: tree.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/tree.c,v
retrieving revision 1.174
diff -c -p -d -r1.174 tree.c
*** tree.c	2000/11/19 08:36:18	1.174
--- tree.c	2000/11/19 20:12:31
*************** int_fits_type_p (c, type)
*** 4186,4192 ****
  {
    /* If the bounds of the type are integers, we can check ourselves.
       Otherwise,. use force_fit_type, which checks against the precision.  */
!   if (TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
        && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST)
      {
        if (TREE_UNSIGNED (type))
--- 4186,4194 ----
  {
    /* If the bounds of the type are integers, we can check ourselves.
       Otherwise,. use force_fit_type, which checks against the precision.  */
!   if (TYPE_MAX_VALUE (type) != NULL_TREE
!       && TYPE_MIN_VALUE (type) != NULL_TREE
!       && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
        && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST)
      {
        if (TREE_UNSIGNED (type))


More information about the Gcc-patches mailing list