This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
build_range_type/build_index_type
- To: egcs-patches at cygnus dot com
- Subject: build_range_type/build_index_type
- From: Mark Mitchell <mark at markmitchell dot com>
- Date: Tue, 3 Nov 1998 22:54:36 -0800
- Cc: Jeff Law <law at cygnus dot com>
- Reply-to: mark at markmitchell dot com
For some reason, these two functions contain much of the same code.
The only real different is that `build_index_type' checks the upper
bound on the range, and, if it is negative, makes it -1, while
`build_range_type' makes it ((size_t) -1), which is probably different
since INT_CSTs are 64-bits, and many machines are 32 bits.
All this is just odd. But, build_index_2_type calls build_range_type,
which means that `build_index_2_type (size_zero_node, x)' and
`build_index_type (x)' are not equivalent. Very odd indeed.
Here's a proposed patch. It assumes that build_index_type's handling
of -1 is correct, and moves it to build_range_type. If this is the
wrong assumption, we should do something else. But, we shouldn't have
25 lines of duplicated code that doesn't quite do the same thing and
doesn't explain itself. :-)
--
Mark Mitchell mark@markmitchell.com
Mark Mitchell Consulting http://www.markmitchell.com
Tue Nov 3 22:36:53 1998 Mark Mitchell <mark@markmitchell.com>
* tree.c (build_range_type): Check for highval == -1, and don't
truncate this value.
(build_index_type): Call build_index_2_type instead of duplicating
build_range_type inline.
Index: tree.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/tree.c,v
retrieving revision 1.48
diff -c -p -r1.48 tree.c
*** tree.c 1998/10/28 22:59:08 1.48
--- tree.c 1998/11/04 06:34:18
*************** tree
*** 4122,4154 ****
build_index_type (maxval)
tree maxval;
{
! register tree itype = make_node (INTEGER_TYPE);
!
! TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
! TYPE_MIN_VALUE (itype) = size_zero_node;
!
! push_obstacks (TYPE_OBSTACK (itype), TYPE_OBSTACK (itype));
! TYPE_MAX_VALUE (itype) = convert (sizetype, maxval);
! pop_obstacks ();
!
! TYPE_MODE (itype) = TYPE_MODE (sizetype);
! TYPE_SIZE (itype) = TYPE_SIZE (sizetype);
! TYPE_SIZE_UNIT (itype) = TYPE_SIZE_UNIT (sizetype);
! TYPE_ALIGN (itype) = TYPE_ALIGN (sizetype);
! if (TREE_CODE (maxval) == INTEGER_CST)
! {
! int maxint = (int) TREE_INT_CST_LOW (maxval);
! /* If the domain should be empty, make sure the maxval
! remains -1 and is not spoiled by truncation. */
! if (INT_CST_LT (maxval, integer_zero_node))
! {
! TYPE_MAX_VALUE (itype) = build_int_2 (-1, -1);
! TREE_TYPE (TYPE_MAX_VALUE (itype)) = sizetype;
! }
! return type_hash_canon (maxint < 0 ? ~maxint : maxint, itype);
! }
! else
! return itype;
}
/* Create a range of some discrete type TYPE (an INTEGER_TYPE,
--- 4122,4128 ----
build_index_type (maxval)
tree maxval;
{
! return build_index_2_type (size_zero_node, maxval);
}
/* Create a range of some discrete type TYPE (an INTEGER_TYPE,
*************** build_range_type (type, lowval, highval)
*** 4168,4175 ****
push_obstacks (TYPE_OBSTACK (itype), TYPE_OBSTACK (itype));
TYPE_MIN_VALUE (itype) = convert (type, lowval);
! TYPE_MAX_VALUE (itype) = highval ? convert (type, highval) : NULL;
pop_obstacks ();
TYPE_PRECISION (itype) = TYPE_PRECISION (type);
TYPE_MODE (itype) = TYPE_MODE (type);
--- 4142,4157 ----
push_obstacks (TYPE_OBSTACK (itype), TYPE_OBSTACK (itype));
TYPE_MIN_VALUE (itype) = convert (type, lowval);
! TYPE_MAX_VALUE (itype) = highval ? convert (type, highval) : NULL_TREE;
pop_obstacks ();
+
+ /* The value -1 for HIGH_VAL is special, so we take care to
+ preserve it. */
+ if (highval && INT_CST_LT (highval, integer_zero_node))
+ {
+ TYPE_MAX_VALUE (itype) = build_int_2 (-1, -1);
+ TREE_TYPE (TYPE_MAX_VALUE (itype)) = type;
+ }
TYPE_PRECISION (itype) = TYPE_PRECISION (type);
TYPE_MODE (itype) = TYPE_MODE (type);