]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix validity checks for named parameter associations
authorPiotr Trojanek <trojanek@adacore.com>
Tue, 30 Jul 2024 10:30:08 +0000 (12:30 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 23 Aug 2024 08:51:03 +0000 (10:51 +0200)
When iterating over actual and formal parameters, we should use
First_Actual/Next_Actual and not simply First/Next, because the
order of actual parameters might be different than the order of
formal parameters obtained with First_Formal/Next_Formal.

This patch fixes a glitch in validity checks for actual parameters
and applies the same fix to other misuses of First/Next as well.

gcc/ada/

* checks.adb (Ensure_Valid): Use First_Actual/Next_Actual.
* exp_ch6.adb (Is_Direct_Deep_Call): Likewise.
* exp_util.adb (Type_Of_Formal): Likewise.
* sem_util.adb (Is_Container_Element): Likewise; cleanup
membership test by using a subtype.

gcc/ada/checks.adb
gcc/ada/exp_ch6.adb
gcc/ada/exp_util.adb
gcc/ada/sem_util.adb

index 77043ca07c214c253009396f219952cccce54795..343f027608b5e560879e81033b5d76eafe943358 100644 (file)
@@ -6840,7 +6840,7 @@ package body Checks is
                      --  OUT parameter for which we are the argument.
 
                      F := First_Formal (E);
-                     A := First (L);
+                     A := First_Actual (P);
                      while Present (F) loop
                         if A = N
                           and then (Ekind (F) = E_Out_Parameter
@@ -6850,7 +6850,7 @@ package body Checks is
                         end if;
 
                         Next_Formal (F);
-                        Next (A);
+                        Next_Actual (A);
                      end loop;
                   end if;
                end if;
index 24b754731d22989e7059cf4903532e445744406d..420d5f44a69eafd991251b795711ea878b3c68da 100644 (file)
@@ -3879,7 +3879,7 @@ package body Exp_Ch6 is
                Formal : Entity_Id;
 
             begin
-               Actual := First (Parameter_Associations (Call_Node));
+               Actual := First_Actual (Call_Node);
                Formal := First_Formal (Subp);
                while Present (Actual)
                  and then Present (Formal)
@@ -3891,7 +3891,7 @@ package body Exp_Ch6 is
                      return True;
                   end if;
 
-                  Next (Actual);
+                  Next_Actual (Actual);
                   Next_Formal (Formal);
                end loop;
             end;
index 392bf3a511e6bee691933ec98142e547397ed267..756638c52c24f9c9fc2345568b84ab9e10656421 100644 (file)
@@ -13070,14 +13070,14 @@ package body Exp_Util is
       begin
          --  Examine the list of actual and formal parameters in parallel
 
-         A := First (Parameter_Associations (Call));
+         A := First_Actual (Call);
          F := First_Formal (Entity (Name (Call)));
          while Present (A) and then Present (F) loop
             if A = Actual then
                return Etype (F);
             end if;
 
-            Next (A);
+            Next_Actual (A);
             Next_Formal (F);
          end loop;
 
index ab7fcf8dfd11b5912bffb96194a620a5117f6ab7..688d9232b443296ab4dd8cb09aab71a16ab643ce 100644 (file)
@@ -15918,10 +15918,8 @@ package body Sem_Util is
                elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
                   return False;
 
-               elsif Nkind (Parent (Par)) in
-                       N_Function_Call            |
-                       N_Procedure_Call_Statement |
-                       N_Entry_Call_Statement
+               elsif Nkind (Parent (Par)) in N_Entry_Call_Statement
+                                           | N_Subprogram_Call
                then
                   --  Check that the element is not part of an actual for an
                   --  in-out parameter.
@@ -15932,14 +15930,14 @@ package body Sem_Util is
 
                   begin
                      F := First_Formal (Entity (Name (Parent (Par))));
-                     A := First (Parameter_Associations (Parent (Par)));
+                     A := First_Actual (Parent (Par));
                      while Present (F) loop
                         if A = Par and then Ekind (F) /= E_In_Parameter then
                            return False;
                         end if;
 
                         Next_Formal (F);
-                        Next (A);
+                        Next_Actual (A);
                      end loop;
                   end;