aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sem_ch6.adb
diff options
context:
space:
mode:
authorPiotr Trojanek <trojanek@adacore.com>2022-01-20 20:12:52 +0100
committerPierre-Marie de Rodat <derodat@adacore.com>2022-05-10 08:19:26 +0000
commitd421523a42d50e1004d5bbe30e4c45b2b98f1a03 (patch)
treef64dc658937598483de20636349aa013fd9b5ae9 /gcc/ada/sem_ch6.adb
parent3a978538036cd43d629c7b003c5ee6c8b3bf2c98 (diff)
[Ada] Refine iteration from entities to formals
When matching formal parameters from spec and body it is cleaner and more efficient to iterate with First_Formal/Next_Formal and not with First_Entity/Next_Entity. The previous iteration could unintentionally pick entities from within the subprogram body, e.g. objects declared within the subprogram. gcc/ada/ * sem_ch6.adb (Analyze_Subprogram_Body_Helper): Replace First_Entity/Next_Entity with First_Formal/Next_Formal; rename E1/E2 to F1/F2.
Diffstat (limited to 'gcc/ada/sem_ch6.adb')
-rw-r--r--gcc/ada/sem_ch6.adb24
1 files changed, 12 insertions, 12 deletions
diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb
index 22faeb6afb3..510cad2c70a 100644
--- a/gcc/ada/sem_ch6.adb
+++ b/gcc/ada/sem_ch6.adb
@@ -5407,8 +5407,8 @@ package body Sem_Ch6 is
-- Check for variables that are never modified
declare
- E1 : Entity_Id;
- E2 : Entity_Id;
+ F1 : Entity_Id;
+ F2 : Entity_Id;
begin
-- If there is a separate spec, then transfer Never_Set_In_Source
@@ -5417,21 +5417,21 @@ package body Sem_Ch6 is
-- the body entities, not the spec entities.
if Present (Spec_Id) then
- E1 := First_Entity (Spec_Id);
- while Present (E1) loop
- if Ekind (E1) = E_Out_Parameter then
- E2 := First_Entity (Body_Id);
- while Present (E2) loop
- exit when Chars (E1) = Chars (E2);
- Next_Entity (E2);
+ F1 := First_Formal (Spec_Id);
+ while Present (F1) loop
+ if Ekind (F1) = E_Out_Parameter then
+ F2 := First_Formal (Body_Id);
+ while Present (F2) loop
+ exit when Chars (F1) = Chars (F2);
+ Next_Formal (F2);
end loop;
- if Present (E2) then
- Set_Never_Set_In_Source (E2, Never_Set_In_Source (E1));
+ if Present (F2) then
+ Set_Never_Set_In_Source (F2, Never_Set_In_Source (F1));
end if;
end if;
- Next_Entity (E1);
+ Next_Formal (F1);
end loop;
end if;