Commit 4e6602a8 by Eric Botcazou Committed by Eric Botcazou

decl.c (gnat_to_gnu_entity): Pass correct arguments to create_field_decl.

	* 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.
	<E_Array_Subtype>: Reorder and simplify handling of special cases.
	Rewrite computation of the maximum size.  Use consistent naming.
	* gcc-interface/trans.c (Attribute_to_gnu) <Attr_Length>: Swap
	comparison order for consistency.  Use generic integer node to
	build the operator and fold the result.

From-SVN: r148962
parent b3c54c8f
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.
<E_Array_Subtype>: Reorder and simplify handling of special cases.
Rewrite computation of the maximum size. Use consistent naming.
* gcc-interface/trans.c (Attribute_to_gnu) <Attr_Length>: Swap
comparison order for consistency. Use generic integer node to
build the operator and fold the result.
2009-06-25 Vincent Celier <celier@adacore.com> 2009-06-25 Vincent Celier <celier@adacore.com>
* vms_data.ads: Minor comment change * vms_data.ads: Minor comment change
......
...@@ -1552,43 +1552,38 @@ Attribute_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, int attribute) ...@@ -1552,43 +1552,38 @@ Attribute_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, int attribute)
/* We used to compute the length as max (hb - lb + 1, 0), /* We used to compute the length as max (hb - lb + 1, 0),
which could overflow for some cases of empty arrays, e.g. which could overflow for some cases of empty arrays, e.g.
when lb == index_type'first. We now compute the length as when lb == index_type'first. We now compute the length as
(hb < lb) ? 0 : hb - lb + 1, which would only overflow in (hb >= lb) ? hb - lb + 1 : 0, which would only overflow in
much rarer cases, for extremely large arrays we expect much rarer cases, for extremely large arrays we expect
never to encounter in practice. In addition, the former never to encounter in practice. In addition, the former
computation required the use of potentially constraining computation required the use of potentially constraining
signed arithmetic while the latter doesn't. Note that the signed arithmetic while the latter doesn't. Note that
comparison must be done in the original index base type, the comparison must be done in the original index type,
otherwise the conversion of either bound to gnu_compute_type to avoid any overflow during the conversion. */
may overflow. */ tree comp_type = get_base_type (gnu_result_type);
tree index_type = TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type));
tree gnu_compute_type = get_base_type (gnu_result_type); tree lb = TYPE_MIN_VALUE (index_type);
tree hb = TYPE_MAX_VALUE (index_type);
tree index_type
= TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type));
tree lb
= convert (gnu_compute_type, TYPE_MIN_VALUE (index_type));
tree hb
= convert (gnu_compute_type, TYPE_MAX_VALUE (index_type));
gnu_result gnu_result
= build3 = build_binary_op (PLUS_EXPR, comp_type,
(COND_EXPR, gnu_compute_type, build_binary_op (MINUS_EXPR,
build_binary_op (LT_EXPR, get_base_type (index_type), comp_type,
TYPE_MAX_VALUE (index_type), convert (comp_type, hb),
TYPE_MIN_VALUE (index_type)), convert (comp_type, lb)),
convert (gnu_compute_type, integer_zero_node), convert (comp_type, integer_one_node));
build_binary_op gnu_result
(PLUS_EXPR, gnu_compute_type, = build_cond_expr (comp_type,
build_binary_op (MINUS_EXPR, gnu_compute_type, hb, lb), build_binary_op (GE_EXPR,
convert (gnu_compute_type, integer_one_node))); integer_type_node,
hb, lb),
gnu_result,
convert (comp_type, integer_zero_node));
} }
} }
/* If this has a PLACEHOLDER_EXPR, qualify it by the object we are /* If this has a PLACEHOLDER_EXPR, qualify it by the object we are
handling. Note that these attributes could not have been used on handling. Note that these attributes could not have been used on
an unconstrained array type. */ an unconstrained array type. */
gnu_result = SUBSTITUTE_PLACEHOLDER_IN_EXPR (gnu_result, gnu_result = SUBSTITUTE_PLACEHOLDER_IN_EXPR (gnu_result, gnu_prefix);
gnu_prefix);
/* Cache the expression we have just computed. Since we want to do it /* Cache the expression we have just computed. Since we want to do it
at runtime, we force the use of a SAVE_EXPR and let the gimplifier at runtime, we force the use of a SAVE_EXPR and let the gimplifier
......
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