From: Piotr Trojanek Date: Thu, 20 Jan 2022 19:12:52 +0000 (+0100) Subject: [Ada] Refine iteration from entities to formals X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d421523a42d50e1004d5bbe30e4c45b2b98f1a03;p=platform%2Fupstream%2Fgcc.git [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. --- diff --git a/gcc/ada/sem_ch6.adb b/gcc/ada/sem_ch6.adb index 22faeb6..510cad2 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;