From: Eric Botcazou <[email protected]>
The processing of static array aggregates in Exp_Aggr requires that their
bounds be representable as Int(eger) values for practical purposes, and
the previous changes have exposed another path where this is not checked.
This introduces a UI_Are_In_Int_Range local predicate for convenience.
gcc/ada/ChangeLog:
* exp_aggr.adb (UI_Are_In_Int_Range): New predicate.
(Aggr_Size_OK): Use it.
(Flatten): Likewise.
(Packed_Array_Aggregate_Handled): Likewise.
(Static_Array_Aggregate): Likewise.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/exp_aggr.adb | 37 +++++++++++++++++++++----------------
1 file changed, 21 insertions(+), 16 deletions(-)
diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index 1cfc97b5bc6..c34df840401 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -161,6 +161,10 @@ package body Exp_Aggr is
-- statement of variant part will usually be small and probably in near
-- sorted order.
+ function UI_Are_In_Int_Range (Left, Right : Uint) return Boolean is
+ (UI_Is_In_Int_Range (Left) and then UI_Is_In_Int_Range (Right));
+ -- Return True if both Left and Right are in Int range
+
------------------------------------------------------
-- Local subprograms for Record Aggregate Expansion --
------------------------------------------------------
@@ -777,10 +781,7 @@ package body Exp_Aggr is
-- Bounds must be in integer range, for later array construction
- if not UI_Is_In_Int_Range (Lov)
- or else
- not UI_Is_In_Int_Range (Hiv)
- then
+ if not UI_Are_In_Int_Range (Lov, Hiv) then
return False;
end if;
@@ -4504,13 +4505,13 @@ package body Exp_Aggr is
-- present we can proceed since the bounds can be obtained from the
-- aggregate.
- if not Compile_Time_Known_Value (Blo) and then Others_Present
- then
+ if not Compile_Time_Known_Value (Blo) and then Others_Present then
return False;
end if;
- if not (UI_Is_In_Int_Range (Lov) and UI_Is_In_Int_Range (Hiv)) then
- -- guard against raising C_E in UI_To_Int
+ -- Guard against raising C_E in UI_To_Int
+
+ if not UI_Are_In_Int_Range (Lov, Hiv) then
return False;
end if;
@@ -9100,17 +9101,15 @@ package body Exp_Aggr is
end if;
declare
- Bounds_Vals : Range_Values;
+ Bounds_Vals : constant Range_Values :=
+ (First => Expr_Value (Bounds.First),
+ Last => Expr_Value (Bounds.Last));
-- Compile-time known values of bounds
- begin
- -- Or are silly out of range of int bounds
- Bounds_Vals.First := Expr_Value (Bounds.First);
- Bounds_Vals.Last := Expr_Value (Bounds.Last);
+ begin
+ -- Guard against raising C_E in UI_To_Int
- if not UI_Is_In_Int_Range (Bounds_Vals.First)
- or else
- not UI_Is_In_Int_Range (Bounds_Vals.Last)
+ if not UI_Are_In_Int_Range (Bounds_Vals.First, Bounds_Vals.Last)
then
return False;
end if;
@@ -9497,6 +9496,12 @@ package body Exp_Aggr is
return False;
end if;
+ -- Guard against raising C_E in UI_To_Int
+
+ if not UI_Are_In_Int_Range (Intval (Lo), Intval (Hi)) then
+ return False;
+ end if;
+
-- Create a positional aggregate with the right number of
-- copies of the expression.
--
2.43.0