https://gcc.gnu.org/g:5fac2f40b096dcc8d5cc3b5053d91ededeaf32b8

commit r15-10501-g5fac2f40b096dcc8d5cc3b5053d91ededeaf32b8
Author: Ronan Desplanques <[email protected]>
Date:   Thu Mar 6 12:54:44 2025 +0100

    ada: Set Ekind early in object declarations
    
    Setting the proper Ekind on object entities was once needed to catch
    cases of premature usages. The introduction of Is_Self_Hidden changed
    that, so this patch replaces the Mutate_Ekind calls in the natural
    place.
    
    gcc/ada/ChangeLog:
    
            * sem_ch3.adb (Analyze_Object_Declaration): Call Mutate_Ekind 
earlier.

Diff:
---
 gcc/ada/sem_ch3.adb | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index 85940f2e7cf5..2d96545067f6 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -4363,6 +4363,12 @@ package body Sem_Ch3 is
    --  Start of processing for Analyze_Object_Declaration
 
    begin
+      if Constant_Present (N) then
+         Mutate_Ekind (Id, E_Constant);
+      else
+         Mutate_Ekind (Id, E_Variable);
+      end if;
+
       --  There are three kinds of implicit types generated by an
       --  object declaration:
 
@@ -4442,7 +4448,6 @@ package body Sem_Ch3 is
 
             T := Find_Type_Of_Object (Object_Definition (N), N);
             Set_Etype (Id, T);
-            Mutate_Ekind (Id, E_Variable);
             goto Leave;
          end if;
 
@@ -4468,7 +4473,6 @@ package body Sem_Ch3 is
 
          if Error_Posted (Id) then
             Set_Etype (Id, T);
-            Mutate_Ekind (Id, E_Variable);
             goto Leave;
          end if;
       end if;
@@ -4760,7 +4764,6 @@ package body Sem_Ch3 is
            and then In_Subrange_Of (Etype (Entity (E)), T)
          then
             Set_Is_Known_Valid (Id);
-            Mutate_Ekind (Id, E_Constant);
             Set_Actual_Subtype (Id, Etype (Entity (E)));
          end if;
 
@@ -5009,12 +5012,6 @@ package body Sem_Ch3 is
             --  for discriminants and are thus not indefinite.
 
             elsif Is_Unchecked_Union (T) then
-               if Constant_Present (N) or else Nkind (E) = N_Function_Call then
-                  Mutate_Ekind (Id, E_Constant);
-               else
-                  Mutate_Ekind (Id, E_Variable);
-               end if;
-
                --  If the expression is an aggregate it contains the required
                --  discriminant values but it has not been resolved yet, so do
                --  it now, and treat it as the initial expression of an object
@@ -5075,10 +5072,8 @@ package body Sem_Ch3 is
                   --  "X : Integer := X;".
 
                   if Constant_Present (N) then
-                     Mutate_Ekind         (Id, E_Constant);
                      Set_Is_True_Constant (Id);
                   else
-                     Mutate_Ekind (Id, E_Variable);
                      if Present (E) then
                         Set_Has_Initial_Value (Id);
                      end if;
@@ -5220,12 +5215,9 @@ package body Sem_Ch3 is
       end if;
 
       if Constant_Present (N) then
-         Mutate_Ekind         (Id, E_Constant);
          Set_Is_True_Constant (Id);
 
       else
-         Mutate_Ekind (Id, E_Variable);
-
          --  A variable is set as shared passive if it appears in a shared
          --  passive package, and is at the outer level. This is not done for
          --  entities generated during expansion, because those are always

Reply via email to