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

commit r16-1438-gdf186850f2868f6e78509f25d01bdbf2c3f342fe
Author: Ronan Desplanques <desplanq...@adacore.com>
Date:   Fri Mar 28 12:37:50 2025 +0100

    ada: Remove creation of some unused itypes
    
    Before this patch, Constrain_Index always started by creating an itype
    but then sometimes not using it for anything. This patch makes it so an
    itype is only created when needed.
    
    gcc/ada/ChangeLog:
    
            * sem_ch3.adb (Constrain_Index): Avoid unused itypes.

Diff:
---
 gcc/ada/sem_ch3.adb | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index a5df3f89dac6..23d67eaecc0d 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -15215,17 +15215,21 @@ package body Sem_Ch3 is
       R      : Node_Id := Empty;
       T      : constant Entity_Id := Etype (Index);
       Is_FLB_Index : Boolean := False;
+      Is_Range     : constant Boolean :=
+        Nkind (S) = N_Range
+        or else (Nkind (S) = N_Attribute_Reference
+                 and then Attribute_Name (S) = Name_Range);
+      Is_Indic     : constant Boolean := Nkind (S) = N_Subtype_Indication;
 
    begin
-      Def_Id :=
-        Create_Itype (E_Void, Related_Nod, Related_Id, Suffix, Suffix_Index);
-      Set_Etype (Def_Id, Base_Type (T));
+      if Is_Range or else Is_Indic then
+         Def_Id :=
+           Create_Itype
+             (E_Void, Related_Nod, Related_Id, Suffix, Suffix_Index);
+         Set_Etype (Def_Id, Base_Type (T));
+      end if;
 
-      if Nkind (S) = N_Range
-        or else
-          (Nkind (S) = N_Attribute_Reference
-            and then Attribute_Name (S) = Name_Range)
-      then
+      if Is_Range then
          --  A Range attribute will be transformed into N_Range by Resolve
 
          --  If a range has an Empty upper bound, then remember that for later
@@ -15260,7 +15264,7 @@ package body Sem_Ch3 is
             end if;
          end if;
 
-      elsif Nkind (S) = N_Subtype_Indication then
+      elsif Is_Indic then
 
          --  The parser has verified that this is a discrete indication

Reply via email to