aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/exp_aggr.adb
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2019-12-22 19:37:20 +0100
committerPierre-Marie de Rodat <derodat@adacore.com>2020-06-02 04:58:20 -0400
commit6a987d785122fb015aac527e927818bdc9975a7b (patch)
treea81f8f86b9718d479b7f992bc38ea84d4f38b6d7 /gcc/ada/exp_aggr.adb
parent7b976a0de9d9e130a546dc637ddd52540a577f18 (diff)
downloadgcc-6a987d785122fb015aac527e927818bdc9975a7b.zip
gcc-6a987d785122fb015aac527e927818bdc9975a7b.tar.gz
gcc-6a987d785122fb015aac527e927818bdc9975a7b.tar.bz2
[Ada] Get rid of more references to Universal_Integer in expanded code
2020-06-02 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * exp_aggr.adb (Others_Check): In the positional case, use the general expression for the comparison only when needed. * exp_attr.adb (Expand_Fpt_Attribute;): Use a simple conversion to the target type instead of an unchecked conversion to the base type to do the range check, as in the other cases. (Expand_N_Attribute_Reference) <Attribute_Storage_Size>: Do the Max operation in the type of the storage size variable, and use Convert_To as in the other cases. * tbuild.adb (Convert_To): Do not get rid of an intermediate conversion to Universal_Integer here... * sem_res.adb (Simplify_Type_Conversion): ...but here instead.
Diffstat (limited to 'gcc/ada/exp_aggr.adb')
-rw-r--r--gcc/ada/exp_aggr.adb61
1 files changed, 43 insertions, 18 deletions
diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 05508d8..dad83d4 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -5853,26 +5853,51 @@ package body Exp_Aggr is
-- raise Constraint_Error;
-- end if;
+ -- in the general case, but the following simpler test:
+
+ -- [constraint_error when
+ -- Aggr_Lo + (Nb_Elements - 1) > Aggr_Hi];
+
+ -- instead if the index type is a signed integer.
+
elsif Nb_Elements > Uint_0 then
- Cond :=
- Make_Op_Gt (Loc,
- Left_Opnd =>
- Make_Op_Add (Loc,
- Left_Opnd =>
- Make_Attribute_Reference (Loc,
- Prefix => New_Occurrence_Of (Ind_Typ, Loc),
- Attribute_Name => Name_Pos,
- Expressions =>
- New_List
- (Duplicate_Subexpr_Move_Checks (Aggr_Lo))),
- Right_Opnd => Make_Integer_Literal (Loc, Nb_Elements - 1)),
+ if Nb_Elements = Uint_1 then
+ Cond :=
+ Make_Op_Gt (Loc,
+ Left_Opnd => Duplicate_Subexpr_Move_Checks (Aggr_Lo),
+ Right_Opnd => Duplicate_Subexpr_Move_Checks (Aggr_Hi));
+
+ elsif Is_Signed_Integer_Type (Ind_Typ) then
+ Cond :=
+ Make_Op_Gt (Loc,
+ Left_Opnd =>
+ Make_Op_Add (Loc,
+ Left_Opnd => Duplicate_Subexpr_Move_Checks (Aggr_Lo),
+ Right_Opnd =>
+ Make_Integer_Literal (Loc, Nb_Elements - 1)),
+ Right_Opnd => Duplicate_Subexpr_Move_Checks (Aggr_Hi));
- Right_Opnd =>
- Make_Attribute_Reference (Loc,
- Prefix => New_Occurrence_Of (Ind_Typ, Loc),
- Attribute_Name => Name_Pos,
- Expressions => New_List (
- Duplicate_Subexpr_Move_Checks (Aggr_Hi))));
+ else
+ Cond :=
+ Make_Op_Gt (Loc,
+ Left_Opnd =>
+ Make_Op_Add (Loc,
+ Left_Opnd =>
+ Make_Attribute_Reference (Loc,
+ Prefix => New_Occurrence_Of (Ind_Typ, Loc),
+ Attribute_Name => Name_Pos,
+ Expressions =>
+ New_List
+ (Duplicate_Subexpr_Move_Checks (Aggr_Lo))),
+ Right_Opnd => Make_Integer_Literal (Loc, Nb_Elements - 1)),
+
+ Right_Opnd =>
+ Make_Attribute_Reference (Loc,
+ Prefix => New_Occurrence_Of (Ind_Typ, Loc),
+ Attribute_Name => Name_Pos,
+ Expressions => New_List (
+ Duplicate_Subexpr_Move_Checks (Aggr_Hi))));
+ end if;
-- If we are dealing with an aggregate containing an others choice
-- and discrete choices we generate the following test: