aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Squirek <squirek@adacore.com>2024-04-11 18:30:38 +0000
committerMarc Poulhiès <poulhies@adacore.com>2024-06-10 11:04:00 +0200
commitd8e73ea45fbda12931c90d2b703332dec0e22395 (patch)
tree1a89e565f1201b8cc695c5080d0c2e4b2e636136
parentc936305076919e6e7fcf7e8c6332c897571a2894 (diff)
downloadgcc-d8e73ea45fbda12931c90d2b703332dec0e22395.zip
gcc-d8e73ea45fbda12931c90d2b703332dec0e22395.tar.gz
gcc-d8e73ea45fbda12931c90d2b703332dec0e22395.tar.bz2
ada: Iterator filter ignored on formal loop
This patch fixs an issue where iterator filters for formal container and formal container element loops got silently ignored and remained unexpanded. gcc/ada/ * exp_ch5.adb (Expand_Formal_Container_Element_Loop): Add expansion of filter condition. (Expand_Formal_Container_Loop): Add expansion of filter condition.
-rw-r--r--gcc/ada/exp_ch5.adb45
1 files changed, 37 insertions, 8 deletions
diff --git a/gcc/ada/exp_ch5.adb b/gcc/ada/exp_ch5.adb
index 2973658..f397086 100644
--- a/gcc/ada/exp_ch5.adb
+++ b/gcc/ada/exp_ch5.adb
@@ -4394,6 +4394,18 @@ package body Exp_Ch5 is
Reinit_Field_To_Zero (Init_Name, F_SPARK_Pragma_Inherited);
Mutate_Ekind (Init_Name, E_Loop_Parameter);
+ -- Wrap the block statements with the condition specified in the
+ -- iterator filter when one is present.
+
+ if Present (Iterator_Filter (I_Spec)) then
+ pragma Assert (Ada_Version >= Ada_2022);
+ Set_Statements (Handled_Statement_Sequence (N),
+ New_List (Make_If_Statement (Loc,
+ Condition => Iterator_Filter (I_Spec),
+ Then_Statements =>
+ Statements (Handled_Statement_Sequence (N)))));
+ end if;
+
-- The cursor was marked as a loop parameter to prevent user assignments
-- to it, however this renders the advancement step illegal as it is not
-- possible to change the value of a constant. Flag the advancement step
@@ -4436,6 +4448,7 @@ package body Exp_Ch5 is
Advance : Node_Id;
Init : Node_Id;
New_Loop : Node_Id;
+ Block : Node_Id;
begin
-- For an element iterator, the Element aspect must be present,
@@ -4456,7 +4469,6 @@ package body Exp_Ch5 is
Build_Formal_Container_Iteration
(N, Container, Cursor, Init, Advance, New_Loop);
- Append_To (Stats, Advance);
Mutate_Ekind (Cursor, E_Variable);
Insert_Action (N, Init);
@@ -4481,13 +4493,30 @@ package body Exp_Ch5 is
Convert_To_Iterable_Type (Container, Loc),
New_Occurrence_Of (Cursor, Loc))));
- Set_Statements (New_Loop,
- New_List
- (Make_Block_Statement (Loc,
- Declarations => New_List (Elmt_Decl),
- Handled_Statement_Sequence =>
- Make_Handled_Sequence_Of_Statements (Loc,
- Statements => Stats))));
+ Block :=
+ Make_Block_Statement (Loc,
+ Declarations => New_List (Elmt_Decl),
+ Handled_Statement_Sequence =>
+ Make_Handled_Sequence_Of_Statements (Loc,
+ Statements => Stats));
+
+ -- Wrap the block statements with the condition specified in the
+ -- iterator filter when one is present.
+
+ if Present (Iterator_Filter (I_Spec)) then
+ pragma Assert (Ada_Version >= Ada_2022);
+ Set_Statements (Handled_Statement_Sequence (Block),
+ New_List (
+ Make_If_Statement (Loc,
+ Condition => Iterator_Filter (I_Spec),
+ Then_Statements =>
+ Statements (Handled_Statement_Sequence (Block))),
+ Advance));
+ else
+ Append_To (Stats, Advance);
+ end if;
+
+ Set_Statements (New_Loop, New_List (Block));
-- The element is only modified in expanded code, so it appears as
-- unassigned to the warning machinery. We must suppress this spurious