Commit e1ee5cdc by Richard Henderson Committed by Jeff Law

tree.c (build_range_type): Allow creation of ranges with no maximum.

	* tree.c (build_range_type): Allow creation of ranges with no maximum.
	* dbxout.c (dbxout_range_type): Handle missing TYPE_MAX_VALUE.
	* dwarf2out.c (add_subscript_info): Likewise.
	* dwarfout.c (subscript_data_attribute, byte_size_attribute): Likewise.
	* sdbout.c (plain_type_1): Likewise.
	* stmt.c (pushcase_range, all_cases_count, node_has_high_bound):
	Likewise.
	* fold-const.c (int_const_binop, fold_convert, make_range, fold):
	Likewise.

From-SVN: r17142
parent 8342981f
Fri Dec 19 00:19:42 1997 Richard Henderson <rth@cygnus.com>
* tree.c (build_range_type): Allow creation of ranges with no maximum.
* dbxout.c (dbxout_range_type): Handle missing TYPE_MAX_VALUE.
* dwarf2out.c (add_subscript_info): Likewise.
* dwarfout.c (subscript_data_attribute, byte_size_attribute): Likewise.
* sdbout.c (plain_type_1): Likewise.
* stmt.c (pushcase_range, all_cases_count, node_has_high_bound):
Likewise.
* fold-const.c (int_const_binop, fold_convert, make_range, fold):
Likewise.
Thu Dec 18 17:05:10 1997 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> Thu Dec 18 17:05:10 1997 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* mips.c (fatal): Remove declaration. * mips.c (fatal): Remove declaration.
......
...@@ -954,7 +954,8 @@ dbxout_range_type (type) ...@@ -954,7 +954,8 @@ dbxout_range_type (type)
TREE_INT_CST_LOW (TYPE_MIN_VALUE (type))); TREE_INT_CST_LOW (TYPE_MIN_VALUE (type)));
else else
fprintf (asmfile, ";0"); fprintf (asmfile, ";0");
if (TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST) if (TYPE_MAX_VALUE (type)
&& TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST)
fprintf (asmfile, ";%d;", fprintf (asmfile, ";%d;",
TREE_INT_CST_LOW (TYPE_MAX_VALUE (type))); TREE_INT_CST_LOW (TYPE_MAX_VALUE (type)));
else else
......
...@@ -7195,8 +7195,16 @@ add_subscript_info (type_die, type) ...@@ -7195,8 +7195,16 @@ add_subscript_info (type_die, type)
type_die); type_die);
} }
/* ??? If upper is NULL, the array has unspecified length,
but it does have a lower bound. This happens with Fortran
dimension arr(N:*)
Since the debugger is definitely going to need to know N
to produce useful results, go ahead and output the lower
bound solo, and hope the debugger can cope. */
add_bound_info (subrange_die, DW_AT_lower_bound, lower); add_bound_info (subrange_die, DW_AT_lower_bound, lower);
add_bound_info (subrange_die, DW_AT_upper_bound, upper); if (upper)
add_bound_info (subrange_die, DW_AT_upper_bound, upper);
} }
else else
/* We have an array type with an unspecified length. The DWARF-2 /* We have an array type with an unspecified length. The DWARF-2
......
...@@ -2587,9 +2587,8 @@ subscript_data_attribute (type) ...@@ -2587,9 +2587,8 @@ subscript_data_attribute (type)
/* Output the representation format byte for this dimension. */ /* Output the representation format byte for this dimension. */
ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file,
FMT_CODE (1, FMT_CODE (1, TREE_CODE (lower) == INTEGER_CST,
TREE_CODE (lower) == INTEGER_CST, (upper && TREE_CODE (upper) == INTEGER_CST)));
TREE_CODE (upper) == INTEGER_CST));
/* Output the index type for this dimension. */ /* Output the index type for this dimension. */
...@@ -2675,9 +2674,9 @@ byte_size_attribute (tree_node) ...@@ -2675,9 +2674,9 @@ byte_size_attribute (tree_node)
case ARRAY_TYPE: case ARRAY_TYPE:
{ {
/* The lower bound is zero, so the length is the upper bound + 1. */ /* The lower bound is zero, so the length is the upper bound + 1. */
register tree upper_bound; register tree upper;
upper_bound = TYPE_MAX_VALUE (TYPE_DOMAIN (tree_node)); upper = TYPE_MAX_VALUE (TYPE_DOMAIN (tree_node));
size = (unsigned) TREE_INT_CST_LOW (upper_bound) + 1; size = upper ? (unsigned) TREE_INT_CST_LOW (upper) + 1 : -1;
break; break;
} }
......
...@@ -1215,7 +1215,9 @@ int_const_binop (code, arg1, arg2, notrunc, forsize) ...@@ -1215,7 +1215,9 @@ int_const_binop (code, arg1, arg2, notrunc, forsize)
} }
if (TREE_TYPE (arg1) == sizetype && hi == 0 if (TREE_TYPE (arg1) == sizetype && hi == 0
&& low >= 0 && low <= TREE_INT_CST_LOW (TYPE_MAX_VALUE (sizetype)) && low >= 0
&& (TYPE_MAX_VALUE (sizetype) == NULL
|| low <= TREE_INT_CST_LOW (TYPE_MAX_VALUE (sizetype)))
&& ! overflow && ! overflow
&& ! TREE_OVERFLOW (arg1) && ! TREE_OVERFLOW (arg2)) && ! TREE_OVERFLOW (arg1) && ! TREE_OVERFLOW (arg2))
t = size_int (low); t = size_int (low);
...@@ -1532,25 +1534,34 @@ fold_convert (t, arg1) ...@@ -1532,25 +1534,34 @@ fold_convert (t, arg1)
REAL_VALUE_TYPE l; REAL_VALUE_TYPE l;
REAL_VALUE_TYPE u; REAL_VALUE_TYPE u;
tree type1 = TREE_TYPE (arg1); tree type1 = TREE_TYPE (arg1);
int no_upper_bound;
x = TREE_REAL_CST (arg1); x = TREE_REAL_CST (arg1);
l = real_value_from_int_cst (type1, TYPE_MIN_VALUE (type)); l = real_value_from_int_cst (type1, TYPE_MIN_VALUE (type));
u = real_value_from_int_cst (type1, TYPE_MAX_VALUE (type));
no_upper_bound = (TYPE_MAX_VALUE (type) == NULL);
if (!no_upper_bound)
u = real_value_from_int_cst (type1, TYPE_MAX_VALUE (type));
/* See if X will be in range after truncation towards 0. /* See if X will be in range after truncation towards 0.
To compensate for truncation, move the bounds away from 0, To compensate for truncation, move the bounds away from 0,
but reject if X exactly equals the adjusted bounds. */ but reject if X exactly equals the adjusted bounds. */
#ifdef REAL_ARITHMETIC #ifdef REAL_ARITHMETIC
REAL_ARITHMETIC (l, MINUS_EXPR, l, dconst1); REAL_ARITHMETIC (l, MINUS_EXPR, l, dconst1);
REAL_ARITHMETIC (u, PLUS_EXPR, u, dconst1); if (!no_upper_bound)
REAL_ARITHMETIC (u, PLUS_EXPR, u, dconst1);
#else #else
l--; l--;
u++; if (!no_upper_bound)
u++;
#endif #endif
/* If X is a NaN, use zero instead and show we have an overflow. /* If X is a NaN, use zero instead and show we have an overflow.
Otherwise, range check. */ Otherwise, range check. */
if (REAL_VALUE_ISNAN (x)) if (REAL_VALUE_ISNAN (x))
overflow = 1, x = dconst0; overflow = 1, x = dconst0;
else if (! (REAL_VALUES_LESS (l, x) && REAL_VALUES_LESS (x, u))) else if (! (REAL_VALUES_LESS (l, x)
&& !no_upper_bound
&& REAL_VALUES_LESS (x, u)))
overflow = 1; overflow = 1;
#ifndef REAL_ARITHMETIC #ifndef REAL_ARITHMETIC
...@@ -2922,11 +2933,22 @@ make_range (exp, pin_p, plow, phigh) ...@@ -2922,11 +2933,22 @@ make_range (exp, pin_p, plow, phigh)
if (TREE_UNSIGNED (type) && ! TREE_UNSIGNED (TREE_TYPE (exp))) if (TREE_UNSIGNED (type) && ! TREE_UNSIGNED (TREE_TYPE (exp)))
{ {
tree equiv_type = type_for_mode (TYPE_MODE (type), 1); tree equiv_type = type_for_mode (TYPE_MODE (type), 1);
tree high_positive tree high_positive;
= fold (build (RSHIFT_EXPR, type,
convert (type, /* A range without an upper bound is, naturally, unbounded.
TYPE_MAX_VALUE (equiv_type)), Since convert would have cropped a very large value, use
convert (type, integer_one_node))); the max value for the destination type. */
high_positive = TYPE_MAX_VALUE (equiv_type);
if (!high_positive)
{
high_positive = TYPE_MAX_VALUE (type);
if (!high_positive)
abort();
}
high_positive = fold (build (RSHIFT_EXPR, type,
convert (type, high_positive),
convert (type, integer_one_node)));
/* If the low bound is specified, "and" the range with the /* If the low bound is specified, "and" the range with the
range for which the original unsigned value will be range for which the original unsigned value will be
...@@ -4914,6 +4936,7 @@ fold (expr) ...@@ -4914,6 +4936,7 @@ fold (expr)
if (operand_equal_p (arg0, arg1, 0)) if (operand_equal_p (arg0, arg1, 0))
return arg0; return arg0;
if (INTEGRAL_TYPE_P (type) if (INTEGRAL_TYPE_P (type)
&& TYPE_MAX_VALUE (type)
&& operand_equal_p (arg1, TYPE_MAX_VALUE (type), 1)) && operand_equal_p (arg1, TYPE_MAX_VALUE (type), 1))
return omit_one_operand (type, arg1, arg0); return omit_one_operand (type, arg1, arg0);
goto associate; goto associate;
...@@ -5397,6 +5420,8 @@ fold (expr) ...@@ -5397,6 +5420,8 @@ fold (expr)
&& ! (TREE_CONSTANT (cval1) && TREE_CONSTANT (cval2)) && ! (TREE_CONSTANT (cval1) && TREE_CONSTANT (cval2))
&& TREE_TYPE (cval1) == TREE_TYPE (cval2) && TREE_TYPE (cval1) == TREE_TYPE (cval2)
&& INTEGRAL_TYPE_P (TREE_TYPE (cval1)) && INTEGRAL_TYPE_P (TREE_TYPE (cval1))
&& TYPE_MAX_VALUE (TREE_TYPE (cval1))
&& TYPE_MAX_VALUE (TREE_TYPE (cval2))
&& ! operand_equal_p (TYPE_MIN_VALUE (TREE_TYPE (cval1)), && ! operand_equal_p (TYPE_MIN_VALUE (TREE_TYPE (cval1)),
TYPE_MAX_VALUE (TREE_TYPE (cval2)), 0)) TYPE_MAX_VALUE (TREE_TYPE (cval2)), 0))
{ {
......
...@@ -584,6 +584,7 @@ plain_type_1 (type, level) ...@@ -584,6 +584,7 @@ plain_type_1 (type, level)
if (sdb_n_dims < SDB_MAX_DIM) if (sdb_n_dims < SDB_MAX_DIM)
sdb_dims[sdb_n_dims++] sdb_dims[sdb_n_dims++]
= (TYPE_DOMAIN (type) = (TYPE_DOMAIN (type)
&& TYPE_MAX_VALUE (TYPE_DOMAIN (type))
&& TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) == INTEGER_CST && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) == INTEGER_CST
&& TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) == INTEGER_CST && TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) == INTEGER_CST
? (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) ? (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
......
...@@ -4624,10 +4624,16 @@ pushcase_range (value1, value2, converter, label, duplicate) ...@@ -4624,10 +4624,16 @@ pushcase_range (value1, value2, converter, label, duplicate)
/* Fail if the range is empty. Do this before any conversion since /* Fail if the range is empty. Do this before any conversion since
we want to allow out-of-range empty ranges. */ we want to allow out-of-range empty ranges. */
if (tree_int_cst_lt (value2, value1)) if (value2 && tree_int_cst_lt (value2, value1))
return 4; return 4;
value1 = (*converter) (nominal_type, value1); value1 = (*converter) (nominal_type, value1);
/* If the max was unbounded, use the max of the nominal_type we are
converting to. Do this after the < check above to suppress false
positives. */
if (!value2)
value2 = TYPE_MAX_VALUE (nominal_type);
value2 = (*converter) (nominal_type, value2); value2 = (*converter) (nominal_type, value2);
/* Fail if these values are out of range. */ /* Fail if these values are out of range. */
...@@ -4955,6 +4961,7 @@ all_cases_count (type, spareness) ...@@ -4955,6 +4961,7 @@ all_cases_count (type, spareness)
default: default:
case INTEGER_TYPE: case INTEGER_TYPE:
if (TREE_CODE (TYPE_MIN_VALUE (type)) != INTEGER_CST if (TREE_CODE (TYPE_MIN_VALUE (type)) != INTEGER_CST
|| TYPE_MAX_VALUE (type) == NULL
|| TREE_CODE (TYPE_MAX_VALUE (type)) != INTEGER_CST) || TREE_CODE (TYPE_MAX_VALUE (type)) != INTEGER_CST)
return -1; return -1;
else else
...@@ -6194,6 +6201,11 @@ node_has_high_bound (node, index_type) ...@@ -6194,6 +6201,11 @@ node_has_high_bound (node, index_type)
tree high_plus_one; tree high_plus_one;
case_node_ptr pnode; case_node_ptr pnode;
/* If there is no upper bound, obviously no test is needed. */
if (TYPE_MAX_VALUE (index_type) == NULL)
return 1;
/* If the upper bound of this node is the highest value in the type /* If the upper bound of this node is the highest value in the type
of the index expression, we need not test against it. */ of the index expression, we need not test against it. */
......
...@@ -4002,19 +4002,25 @@ build_range_type (type, lowval, highval) ...@@ -4002,19 +4002,25 @@ build_range_type (type, lowval, highval)
push_obstacks (TYPE_OBSTACK (itype), TYPE_OBSTACK (itype)); push_obstacks (TYPE_OBSTACK (itype), TYPE_OBSTACK (itype));
TYPE_MIN_VALUE (itype) = convert (type, lowval); TYPE_MIN_VALUE (itype) = convert (type, lowval);
TYPE_MAX_VALUE (itype) = convert (type, highval); TYPE_MAX_VALUE (itype) = highval ? convert (type, highval) : NULL;
pop_obstacks (); pop_obstacks ();
TYPE_PRECISION (itype) = TYPE_PRECISION (type); TYPE_PRECISION (itype) = TYPE_PRECISION (type);
TYPE_MODE (itype) = TYPE_MODE (type); TYPE_MODE (itype) = TYPE_MODE (type);
TYPE_SIZE (itype) = TYPE_SIZE (type); TYPE_SIZE (itype) = TYPE_SIZE (type);
TYPE_ALIGN (itype) = TYPE_ALIGN (type); TYPE_ALIGN (itype) = TYPE_ALIGN (type);
if ((TREE_CODE (lowval) == INTEGER_CST) if (TREE_CODE (lowval) == INTEGER_CST)
&& (TREE_CODE (highval) == INTEGER_CST))
{ {
HOST_WIDE_INT highint = TREE_INT_CST_LOW (highval); HOST_WIDE_INT lowint, highint;
HOST_WIDE_INT lowint = TREE_INT_CST_LOW (lowval); int maxint;
int maxint = (int) (highint - lowint);
lowint = TREE_INT_CST_LOW (lowval);
if (highval && TREE_CODE (highval) == INTEGER_CST)
highint = TREE_INT_CST_LOW (highval);
else
highint = (~(unsigned HOST_WIDE_INT)0) >> 1;
maxint = (int) (highint - lowint);
return type_hash_canon (maxint < 0 ? ~maxint : maxint, itype); return type_hash_canon (maxint < 0 ? ~maxint : maxint, itype);
} }
else else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment