]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix internal error on loop iterator filter with -gnatVa
authorEric Botcazou <ebotcazou@adacore.com>
Wed, 17 May 2023 15:05:14 +0000 (17:05 +0200)
committerEric Botcazou <ebotcazou@adacore.com>
Thu, 15 Jun 2023 14:46:50 +0000 (16:46 +0200)
The problem is that the condition of the iterator filter is expanded early,
before it is integrated into an if statement of the loop body, so there is
no place to attach the actions generated by this expansion.

This happens only for simple loops, i.e. with a parameter specification, so
the fix uses the same approach for them as for loops based on iterators.

gcc/ada/

* sinfo.ads (Iterator_Filter): Document field.
* sem_ch5.adb (Analyze_Iterator_Specification): Move comment around.
(Analyze_Loop_Parameter_Specification): Only preanalyze the iterator
filter, if any.
* exp_ch5.adb (Expand_N_Loop_Statement): Analyze the new list built
when an iterator filter is present.

gcc/ada/exp_ch5.adb
gcc/ada/sem_ch5.adb
gcc/ada/sinfo.ads

index 265e1a74b9344c4ce91e563946c4da03bc38e967..d605f75d147e0a57c06545978264620812d5045f 100644 (file)
@@ -5610,6 +5610,7 @@ package body Exp_Ch5 is
                   New_List (Make_If_Statement (Loc,
                     Condition => Iterator_Filter (LPS),
                     Then_Statements => Stats)));
+               Analyze_List (Statements (N));
             end if;
 
             --  Deal with loop over predicates
index ab5a2083a00dbafd69533ee02947e06030de0a6a..6b8f9e43183bd56394bc936b259a2c854aa10cac 100644 (file)
@@ -2853,10 +2853,10 @@ package body Sem_Ch5 is
          end if;
       end if;
 
-      if Present (Iterator_Filter (N)) then
-         --  Preanalyze the filter. Expansion will take place when enclosing
-         --  loop is expanded.
+      --  Preanalyze the filter. Expansion will take place when enclosing
+      --  loop is expanded.
 
+      if Present (Iterator_Filter (N)) then
          Preanalyze_And_Resolve (Iterator_Filter (N), Standard_Boolean);
       end if;
    end Analyze_Iterator_Specification;
@@ -3570,8 +3570,11 @@ package body Sem_Ch5 is
          end;
       end if;
 
+      --  Preanalyze the filter. Expansion will take place when enclosing
+      --  loop is expanded.
+
       if Present (Iterator_Filter (N)) then
-         Analyze_And_Resolve (Iterator_Filter (N), Standard_Boolean);
+         Preanalyze_And_Resolve (Iterator_Filter (N), Standard_Boolean);
       end if;
 
       --  A loop parameter cannot be effectively volatile (SPARK RM 7.1.3(4)).
index c25db08bc964d5df8c90382657c3f878953a96de..79fef3e004681f511553953c3d0b8d3d1565a689 100644 (file)
@@ -1899,6 +1899,11 @@ package Sinfo is
    --    Present in variable reference markers. Set when the original variable
    --    reference constitutes a write of the variable.
 
+   --  Iterator_Filter
+   --    Present in N_Loop_Parameter_Specification and N_Iterator_Specification
+   --    nodes for Ada 2022. It is used to store the condition present in the
+   --    eponymous Ada 2022 construct.
+
    --  Itype
    --    Used in N_Itype_Reference node to reference an itype for which it is
    --    important to ensure that it is defined. See description of this node