https://gcc.gnu.org/g:8719b1843bc0f24a79433c8685d09cf822af0db7

commit r15-3105-g8719b1843bc0f24a79433c8685d09cf822af0db7
Author: Piotr Trojanek <troja...@adacore.com>
Date:   Tue Jul 30 12:30:08 2024 +0200

    ada: Fix validity checks for named parameter associations
    
    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.

Diff:
---
 gcc/ada/checks.adb   |  4 ++--
 gcc/ada/exp_ch6.adb  |  4 ++--
 gcc/ada/exp_util.adb |  4 ++--
 gcc/ada/sem_util.adb | 10 ++++------
 4 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb
index 77043ca07c21..343f027608b5 100644
--- a/gcc/ada/checks.adb
+++ b/gcc/ada/checks.adb
@@ -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;
diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb
index 24b754731d22..420d5f44a69e 100644
--- a/gcc/ada/exp_ch6.adb
+++ b/gcc/ada/exp_ch6.adb
@@ -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;
diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index 392bf3a511e6..756638c52c24 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -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;
 
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index ab7fcf8dfd11..688d9232b443 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -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;

Reply via email to