Skip to content

Commit 591cb65

Browse files
committed
Allow subtype array constraints
Array constraints may be specified by a subtype as well as a range.
1 parent 9f260a1 commit 591cb65

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

gnat2goto/driver/arrays.adb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,12 +382,24 @@ package body Arrays is
382382
-- is pure
383383

384384
function Make_Array_Default_Initialiser (E : Entity_Id) return Irep is
385+
-- Note this function only works for one dimensional arrays at present.
385386
Idx : constant Node_Id := First_Index (E);
387+
-- The Entity is an array object
388+
-- The first index is a discrete_subtype_definition which
389+
-- may be a subtype_indication or a range.
390+
-- For determining the upper bounds and lower bounds a range is required
391+
-- and if the first index is a subtype_indication, the constraints
392+
-- of the subtype have to be obtained - which should be a range.
393+
Bound_Range : constant Node_Id :=
394+
(if Nkind (Idx) = N_Range
395+
then Idx
396+
else Scalar_Range (Entity (Idx)));
397+
386398
Lbound : constant Irep :=
387-
Typecast_If_Necessary (Do_Expression (Low_Bound (Idx)),
399+
Typecast_If_Necessary (Do_Expression (Low_Bound (Bound_Range)),
388400
CProver_Size_T, Global_Symbol_Table);
389401
Hbound : constant Irep :=
390-
Typecast_If_Necessary (Do_Expression (High_Bound (Idx)),
402+
Typecast_If_Necessary (Do_Expression (High_Bound (Bound_Range)),
391403
CProver_Size_T, Global_Symbol_Table);
392404
Source_Loc : constant Source_Ptr := Sloc (E);
393405
Len : constant Irep :=

0 commit comments

Comments
 (0)