From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Justin Squirek <squirek@adacore.com>
Subject: [COMMITTED 23/30] ada: Iterator filter ignored on formal loop
Date: Mon, 10 Jun 2024 11:07:39 +0200 [thread overview]
Message-ID: <20240610090747.1557638-23-poulhies@adacore.com> (raw)
In-Reply-To: <20240610090747.1557638-1-poulhies@adacore.com>
From: Justin Squirek <squirek@adacore.com>
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.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/exp_ch5.adb | 45 +++++++++++++++++++++++++++++++++++++--------
1 file changed, 37 insertions(+), 8 deletions(-)
diff --git a/gcc/ada/exp_ch5.adb b/gcc/ada/exp_ch5.adb
index 2973658ce98..f397086d73a 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
--
2.45.1
next prev parent reply other threads:[~2024-06-10 9:08 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-10 9:07 [COMMITTED 01/30] ada: Refactor checks for Refined_Global in generic instances Marc Poulhiès
2024-06-10 9:07 ` [COMMITTED 02/30] ada: Refactor checks for Refined_Depends " Marc Poulhiès
2024-06-10 9:07 ` [COMMITTED 03/30] ada: Remove unnecessary guard against empty list Marc Poulhiès
2024-06-10 9:07 ` [COMMITTED 04/30] ada: Fix handling of aspects CPU and Interrupt_Priority Marc Poulhiès
2024-06-10 9:07 ` [COMMITTED 05/30] ada: Cleanup building of error messages for class-wide contracts Marc Poulhiès
2024-06-10 9:07 ` [COMMITTED 06/30] ada: Refactor common code for dynamic and static class-wide preconditions Marc Poulhiès
2024-06-10 9:07 ` [COMMITTED 07/30] ada: Add switch to disable expansion of assertions in CodePeer mode Marc Poulhiès
2024-06-10 9:07 ` [COMMITTED 08/30] ada: Enable inlining for subprograms with multiple return statements Marc Poulhiès
2024-06-10 9:07 ` [COMMITTED 09/30] ada: Simplify check for type without stream operations Marc Poulhiès
2024-06-10 9:07 ` [COMMITTED 10/30] ada: Skip processing of NUL character for attribute Type_Key Marc Poulhiès
2024-06-10 9:07 ` [COMMITTED 11/30] ada: Adjust comments and doc about the new use of restriction No_Streams Marc Poulhiès
2024-06-10 9:07 ` [COMMITTED 12/30] ada: Cleanup repeated code in expansion of stream attributes Marc Poulhiès
2024-06-10 9:07 ` [COMMITTED 13/30] ada: Fix incorrect lower bound presumption in gnatlink Marc Poulhiès
2024-06-10 9:07 ` [COMMITTED 14/30] ada: Remove incorrect assertion in run-time Marc Poulhiès
2024-06-10 9:07 ` [COMMITTED 15/30] ada: Fix usage of SetThreadIdealProcessor Marc Poulhiès
2024-06-10 9:07 ` [COMMITTED 16/30] ada: Fix usage of SetThreadAffinityMask Marc Poulhiès
2024-06-10 9:07 ` [COMMITTED 17/30] ada: Remove streaming facilities from generics for formal containers Marc Poulhiès
2024-06-10 9:07 ` [COMMITTED 18/30] ada: Tune code related to potentially unevaluated expressions Marc Poulhiès
2024-06-10 9:07 ` [COMMITTED 19/30] ada: Fix references to Ada RM in comments Marc Poulhiès
2024-06-10 9:07 ` [COMMITTED 20/30] ada: Further refine 'Super attribute Marc Poulhiès
2024-06-10 9:07 ` [COMMITTED 21/30] ada: Unreferenced warning on abstract subprogram Marc Poulhiès
2024-06-10 9:07 ` [COMMITTED 22/30] ada: Crash checking accessibility level on private type Marc Poulhiès
2024-06-10 9:07 ` Marc Poulhiès [this message]
2024-06-10 9:07 ` [COMMITTED 24/30] ada: Missing style check for extra parentheses in operators Marc Poulhiès
2024-06-10 9:07 ` [COMMITTED 25/30] ada: Resolve compilation issues with container aggregates in draft ACATS B tests Marc Poulhiès
2024-06-10 9:07 ` [COMMITTED 26/30] ada: For freezing, treat an extension or delta aggregate like a regular aggregate Marc Poulhiès
2024-06-10 9:07 ` [COMMITTED 27/30] ada: Minor code adjustment to "not Present" test Marc Poulhiès
2024-06-10 9:07 ` [COMMITTED 28/30] ada: Derived type with convention C must override convention C_Pass_By_Copy Marc Poulhiès
2024-06-10 9:07 ` [COMMITTED 29/30] ada: Storage_Error in indirect call to function returning limited type Marc Poulhiès
2024-06-10 9:07 ` [COMMITTED 30/30] ada: Add support for No_Implicit_Conditionals to nonbinary modular types Marc Poulhiès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240610090747.1557638-23-poulhies@adacore.com \
--to=poulhies@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=squirek@adacore.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).