diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2009-06-26 08:05:31 +0000 |
---|---|---|
committer | Eric Botcazou <ebotcazou@gcc.gnu.org> | 2009-06-26 08:05:31 +0000 |
commit | 4e6602a879928c2775e2a88204b5567ae3599380 (patch) | |
tree | 65651737ef319521e89df0373ead4be544dfe775 /gcc/ada/gcc-interface/trans.c | |
parent | b3c54c8f55b487e77f1e2c881f30781cc784b1d8 (diff) | |
download | gcc-4e6602a879928c2775e2a88204b5567ae3599380.zip gcc-4e6602a879928c2775e2a88204b5567ae3599380.tar.gz gcc-4e6602a879928c2775e2a88204b5567ae3599380.tar.bz2 |
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
Diffstat (limited to 'gcc/ada/gcc-interface/trans.c')
-rw-r--r-- | gcc/ada/gcc-interface/trans.c | 49 |
1 files changed, 22 insertions, 27 deletions
diff --git a/gcc/ada/gcc-interface/trans.c b/gcc/ada/gcc-interface/trans.c index ed9337c..c4b095b 100644 --- a/gcc/ada/gcc-interface/trans.c +++ b/gcc/ada/gcc-interface/trans.c @@ -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), which could overflow for some cases of empty arrays, e.g. 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 never to encounter in practice. In addition, the former computation required the use of potentially constraining - signed arithmetic while the latter doesn't. Note that the - comparison must be done in the original index base type, - otherwise the conversion of either bound to gnu_compute_type - may overflow. */ - - tree gnu_compute_type = get_base_type (gnu_result_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)); - + signed arithmetic while the latter doesn't. Note that + the comparison must be done in the original index type, + to avoid any overflow during the conversion. */ + tree comp_type = get_base_type (gnu_result_type); + tree index_type = TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type)); + tree lb = TYPE_MIN_VALUE (index_type); + tree hb = TYPE_MAX_VALUE (index_type); gnu_result - = build3 - (COND_EXPR, gnu_compute_type, - build_binary_op (LT_EXPR, get_base_type (index_type), - TYPE_MAX_VALUE (index_type), - TYPE_MIN_VALUE (index_type)), - convert (gnu_compute_type, integer_zero_node), - build_binary_op - (PLUS_EXPR, gnu_compute_type, - build_binary_op (MINUS_EXPR, gnu_compute_type, hb, lb), - convert (gnu_compute_type, integer_one_node))); + = build_binary_op (PLUS_EXPR, comp_type, + build_binary_op (MINUS_EXPR, + comp_type, + convert (comp_type, hb), + convert (comp_type, lb)), + convert (comp_type, integer_one_node)); + gnu_result + = build_cond_expr (comp_type, + build_binary_op (GE_EXPR, + 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 handling. Note that these attributes could not have been used on an unconstrained array type. */ - gnu_result = SUBSTITUTE_PLACEHOLDER_IN_EXPR (gnu_result, - gnu_prefix); + gnu_result = SUBSTITUTE_PLACEHOLDER_IN_EXPR (gnu_result, gnu_prefix); /* 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 |