public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-240] [Ada] Refine iteration from entities to formals
@ 2022-05-10  8:22 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2022-05-10  8:22 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:d421523a42d50e1004d5bbe30e4c45b2b98f1a03

commit r13-240-gd421523a42d50e1004d5bbe30e4c45b2b98f1a03
Author: Piotr Trojanek <trojanek@adacore.com>
Date:   Thu Jan 20 20:12:52 2022 +0100

    [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:
---
 gcc/ada/sem_ch6.adb | 24 ++++++++++++------------
 1 file 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;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-10  8:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-10  8:22 [gcc r13-240] [Ada] Refine iteration from entities to formals Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).