diff options
author | Olivier Hainque <hainque@adacore.com> | 2008-04-24 13:24:11 +0000 |
---|---|---|
committer | Olivier Hainque <hainque@gcc.gnu.org> | 2008-04-24 13:24:11 +0000 |
commit | 22a812674cef168628bcf4760ef8faba4bb4cdb0 (patch) | |
tree | d4a267737cd34ccd9e86c61ac0f728f30d7635cc /gcc/ada/trans.c | |
parent | e80d7580e746c0d984bf35968b97b7b88f328e00 (diff) | |
download | gcc-22a812674cef168628bcf4760ef8faba4bb4cdb0.zip gcc-22a812674cef168628bcf4760ef8faba4bb4cdb0.tar.gz gcc-22a812674cef168628bcf4760ef8faba4bb4cdb0.tar.bz2 |
trans.c (Attribute_to_gnu): Length
2008-04-24 Olivier Hainque <hainque@adacore.com>
ada/
* trans.c (Attribute_to_gnu) <case Attr_Length>: Length
* computation
doesn't require signed arithmetic anymore.
testsuite/
* gnat.dg/concat_length.adb: New test.
From-SVN: r134627
Diffstat (limited to 'gcc/ada/trans.c')
-rw-r--r-- | gcc/ada/trans.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/gcc/ada/trans.c b/gcc/ada/trans.c index cb0e8c6..07bdc69 100644 --- a/gcc/ada/trans.c +++ b/gcc/ada/trans.c @@ -1234,9 +1234,16 @@ Attribute_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, int attribute) } else { - tree gnu_compute_type - = signed_or_unsigned_type_for - (0, get_base_type (gnu_result_type)); + /* 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 + 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. */ + + tree gnu_compute_type = get_base_type (gnu_result_type); tree index_type = TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type)); @@ -1245,14 +1252,6 @@ Attribute_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, int attribute) tree hb = convert (gnu_compute_type, TYPE_MAX_VALUE (index_type)); - /* 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 it as (hb < lb) ? 0 : hb - lb + 1, which - could overflow as well, but only for extremely large arrays - which we expect never to encounter in practice. */ - gnu_result = build3 (COND_EXPR, gnu_compute_type, |