+2009-06-26 Eric Botcazou <ebotcazou@adacore.com>
+
+ * gcc-interface/decl.c (gnat_to_gnu_entity) <E_Array_Subtype>: Factor
+ out common predicate. Use the maximum to compute the upper bound of
+ the index type only when it is not wider than sizetype. Perform the
+ comparison in the index type for the generic expression. Use real
+ precision to decide whether to generate special types for debugging
+ information.
+
2009-06-26 Matthew Gingell <gingell@adacore.com>
* adaint.c: Do not use the dummy version of convert_addresses on LynxOS
2009-06-26 Eric Botcazou <ebotcazou@adacore.com>
+ * gcc-interface/decl.c (gnat_to_gnu_entity) <E_Array_Subtype>: Factor
+ out common predicate. Use the maximum to compute the upper bound of
+ the index type only when it is not wider than sizetype. Perform the
+ comparison in the index type for the generic expression. Use real
+ precision to decide whether to generate special types for debugging
+ information.
+
+2009-06-26 Eric Botcazou <ebotcazou@adacore.com>
+
* gcc-interface/decl.c (gnat_to_gnu_entity) <E_Array_Type>: Pass
correct arguments to create_field_decl. Remove redundant iteration.
Rewrite computation of the maximum size.
gnat_base_index = Next_Index (gnat_base_index))
{
tree gnu_index_type = get_unpadded_type (Etype (gnat_index));
+ tree prec = TYPE_RM_SIZE (gnu_index_type);
+ const bool wider_p
+ = (compare_tree_int (prec, TYPE_PRECISION (sizetype)) > 0
+ || (compare_tree_int (prec, TYPE_PRECISION (sizetype)) == 0
+ && TYPE_UNSIGNED (gnu_index_type)
+ != TYPE_UNSIGNED (sizetype)));
tree gnu_orig_min = TYPE_MIN_VALUE (gnu_index_type);
tree gnu_orig_max = TYPE_MAX_VALUE (gnu_index_type);
tree gnu_min = convert (sizetype, gnu_orig_min);
/* Similarly, if one of the values overflows in sizetype and the
range is null, use 1..0 for the sizetype bounds. */
- else if ((TYPE_PRECISION (gnu_index_type)
- > TYPE_PRECISION (sizetype)
- || TYPE_UNSIGNED (gnu_index_type)
- != TYPE_UNSIGNED (sizetype))
+ else if (wider_p
&& TREE_CODE (gnu_min) == INTEGER_CST
&& TREE_CODE (gnu_max) == INTEGER_CST
&& (TREE_OVERFLOW (gnu_min) || TREE_OVERFLOW (gnu_max))
/* If the minimum and maximum values both overflow in sizetype,
but the difference in the original type does not overflow in
sizetype, ignore the overflow indication. */
- else if ((TYPE_PRECISION (gnu_index_type)
- > TYPE_PRECISION (sizetype)
- || TYPE_UNSIGNED (gnu_index_type)
- != TYPE_UNSIGNED (sizetype))
+ else if (wider_p
&& TREE_CODE (gnu_min) == INTEGER_CST
&& TREE_CODE (gnu_max) == INTEGER_CST
&& TREE_OVERFLOW (gnu_min) && TREE_OVERFLOW (gnu_max)
"superflat" case. There are three ways to do this. If
we can prove that the array can never be superflat, we
can just use the high bound of the index subtype. If we
- can prove that the low bound minus one can't overflow,
- we can do this as MAX (hb, lb - 1). Otherwise, we have
- to use the expression hb >= lb ? hb : lb - 1. */
+ can prove that the low bound minus one and the high bound
+ can't overflow, we can do this as MAX (hb, lb - 1). But,
+ otherwise, we have to use (hb >= lb) ? hb : lb - 1. Note
+ that the comparison must be done in the original index
+ type, to avoid any overflow during the conversion. */
gnu_high = size_binop (MINUS_EXPR, gnu_min, size_one_node);
/* If gnu_high is a constant that has overflowed, the array
&& TREE_OVERFLOW (gnu_high))
gnu_high = gnu_max;
- /* gnu_high cannot overflow if the subtype is unsigned and
- sizetype is signed, or if it is a constant that hasn't
- overflowed. */
- else if ((TYPE_UNSIGNED (gnu_index_type)
- && !TYPE_UNSIGNED (sizetype))
- || TREE_CODE (gnu_high) == INTEGER_CST)
+ /* If the index type is not wider and gnu_high is a constant
+ that hasn't overflowed, we can use the maximum. */
+ else if (!wider_p && TREE_CODE (gnu_high) == INTEGER_CST)
gnu_high = size_binop (MAX_EXPR, gnu_max, gnu_high);
else
= build_cond_expr (sizetype,
build_binary_op (GE_EXPR,
integer_type_node,
- gnu_max, gnu_min),
+ gnu_orig_max,
+ gnu_orig_min),
gnu_max, gnu_high);
}
&& TREE_CODE (TREE_TYPE (gnu_index_type))
!= INTEGER_TYPE)
|| TYPE_BIASED_REPRESENTATION_P (gnu_index_type)
- || (TYPE_PRECISION (gnu_index_type)
- > TYPE_PRECISION (sizetype)))
+ || compare_tree_int (prec, TYPE_PRECISION (sizetype)) > 0)
need_index_type_struct = true;
}