https://gcc.gnu.org/g:15fd3020e36e39f6fab6f4c33a88001dd525c4f7

commit r16-1385-g15fd3020e36e39f6fab6f4c33a88001dd525c4f7
Author: Ronan Desplanques <desplanq...@adacore.com>
Date:   Thu Mar 27 12:13:20 2025 +0100

    ada: Factorize some duplicate code
    
    Process_Subtype can be passed either a subtype indication or a subtype
    mark. Before this patch, it branched directly depending on the kind of
    the argument, but there actually was processing common to the two
    branches like resolving the subtype mark. This patch factorizes this
    common processing out of the if statement.
    
    gcc/ada/ChangeLog:
    
            * sem_ch3.adb (Process_Subtype): Factorize code.

Diff:
---
 gcc/ada/sem_ch3.adb | 35 +++++++++++++++++++----------------
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index ff5d0bab99f2..75901bb8eff0 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -22801,6 +22801,7 @@ package body Sem_Ch3 is
       --  Local variables
 
       P               : constant Node_Id := Parent (S);
+      Mark            : Node_Id;
       Def_Id          : Entity_Id;
       Error_Node      : Node_Id;
       Full_View_Id    : Entity_Id;
@@ -22809,22 +22810,28 @@ package body Sem_Ch3 is
    --  Start of processing for Process_Subtype
 
    begin
-      --  Case of no constraints present
+      if Nkind (S) = N_Subtype_Indication then
+         Mark := Subtype_Mark (S);
+      else
+         Mark := S;
+      end if;
 
-      if Nkind (S) /= N_Subtype_Indication then
-         Find_Type (S);
+      Find_Type (Mark);
 
-         --  No way to proceed if the subtype indication is malformed. This
-         --  will happen for example when the subtype indication in an object
-         --  declaration is missing altogether and the expression is analyzed
-         --  as if it were that indication.
+      --  No way to proceed if the subtype indication is malformed. This will
+      --  happen for example when the subtype indication in an object
+      --  declaration is missing altogether and the expression is analyzed as
+      --  if it were that indication.
 
-         if not Is_Entity_Name (S) then
-            return Any_Type;
-         end if;
+      if not Is_Entity_Name (Mark) then
+         return Any_Type;
+      end if;
+
+      Check_Incomplete (Mark);
 
-         Check_Incomplete (S);
+      --  Case of no constraints present
 
+      if Nkind (S) /= N_Subtype_Indication then
          if Excludes_Null then
             --  Create an Itype that is a duplicate of Entity (S) but with the
             --  null-exclusion attribute.
@@ -22886,11 +22893,7 @@ package body Sem_Ch3 is
       --  node (this node is created only if constraints are present).
 
       else
-         Find_Type (Subtype_Mark (S));
-
-         Check_Incomplete (Subtype_Mark (S));
-
-         Subtype_Mark_Id := Entity (Subtype_Mark (S));
+         Subtype_Mark_Id := Entity (Mark);
 
          --  Explicit subtype declaration case

Reply via email to