+2008-04-24 Olivier Hainque <hainque@adacore.com>
+
+ * trans.c (Attribute_to_gnu) <case Attr_Length>: Length computation
+ doesn't require signed arithmetic anymore.
+
2008-04-23 Paolo Bonzini <bonzini@gnu.org>
* trans.c (Attribute_to_gnu): Don't set TREE_INVARIANT.
}
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));
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,
--- /dev/null
+-- { dg-do run }
+
+procedure Concat_Length is
+ type Byte is mod 256;
+ for Byte'Size use 8;
+ type Block is array(Byte range <>) of Integer;
+
+ C0: Block(1..7) := (others => 0);
+ C1: Block(8..255) := (others => 0);
+ C2: Block := C0 & C1;
+begin
+ if C2'Length /= 255 then
+ raise Program_Error;
+ end if;
+end;