diff options
author | Piotr Trojanek <trojanek@adacore.com> | 2024-07-30 12:30:08 +0200 |
---|---|---|
committer | Marc Poulhiès <dkm@gcc.gnu.org> | 2024-08-23 10:51:03 +0200 |
commit | 8719b1843bc0f24a79433c8685d09cf822af0db7 (patch) | |
tree | 217d83b61b08fbdb90706f8dd36c13af13a8ff5f /gcc | |
parent | 4522f1f6e31a606d1c9784eb5790b51e5e194bc7 (diff) | |
download | gcc-8719b1843bc0f24a79433c8685d09cf822af0db7.zip gcc-8719b1843bc0f24a79433c8685d09cf822af0db7.tar.gz gcc-8719b1843bc0f24a79433c8685d09cf822af0db7.tar.bz2 |
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/checks.adb | 4 | ||||
-rw-r--r-- | gcc/ada/exp_ch6.adb | 4 | ||||
-rw-r--r-- | gcc/ada/exp_util.adb | 4 | ||||
-rw-r--r-- | 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 77043ca..343f027 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 24b7547..420d5f4 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 392bf3a..756638c 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 ab7fcf8..688d923 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; |