]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Small tweak to Analyze_Subprogram_Body_Helper
authorEric Botcazou <ebotcazou@adacore.com>
Thu, 8 Jan 2026 10:40:38 +0000 (11:40 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 25 May 2026 08:28:07 +0000 (10:28 +0200)
No functional changes.

gcc/ada/ChangeLog:

* sem_ch6.adb (Analyze_Subprogram_Body_Helper): Pull out the generic
case from the if-statement and put it first.

gcc/ada/sem_ch6.adb

index 022590444537538d284100588047d28267086d41..d78d60b233a725e6cd62136c95d7bb87ae70d247 100644 (file)
@@ -3634,53 +3634,49 @@ package body Sem_Ch6 is
       --  generic specification. Determine whether current scope has a
       --  previous declaration.
 
-      --  If the subprogram body is defined within an instance of the same
-      --  name, the instance appears as a package renaming, and will be hidden
-      --  within the subprogram.
+      if Present (Prev_Id) and then Is_Generic_Subprogram (Prev_Id) then
+         Spec_Id := Prev_Id;
 
-      if Present (Prev_Id)
-        and then not Is_Overloadable (Prev_Id)
-        and then (Nkind (Parent (Prev_Id)) /= N_Package_Renaming_Declaration
-                   or else Comes_From_Source (Prev_Id))
-      then
-         if Is_Generic_Subprogram (Prev_Id) then
-            Spec_Id := Prev_Id;
+         --  A subprogram body is Ghost when it is stand-alone and subject
+         --  to pragma Ghost or when the corresponding spec is Ghost. Set
+         --  the mode now to ensure that any nodes generated during analysis
+         --  and expansion are properly marked as Ghost.
 
-            --  A subprogram body is Ghost when it is stand-alone and subject
-            --  to pragma Ghost or when the corresponding spec is Ghost. Set
-            --  the mode now to ensure that any nodes generated during analysis
-            --  and expansion are properly marked as Ghost.
-
-            Mark_And_Set_Ghost_Body (N, Spec_Id);
+         Mark_And_Set_Ghost_Body (N, Spec_Id);
 
-            --  If the body completes the initial declaration of a compilation
-            --  unit which is subject to pragma Elaboration_Checks, set the
-            --  model specified by the pragma because it applies to all parts
-            --  of the unit.
+         --  If the body completes the initial declaration of a compilation
+         --  unit which is subject to pragma Elaboration_Checks, set the
+         --  model specified by the pragma because it applies to all parts
+         --  of the unit.
 
-            Install_Elaboration_Model (Spec_Id);
+         Install_Elaboration_Model (Spec_Id);
 
-            Set_Is_Compilation_Unit (Body_Id, Is_Compilation_Unit (Spec_Id));
-            Set_Is_Child_Unit       (Body_Id, Is_Child_Unit       (Spec_Id));
+         Set_Is_Compilation_Unit (Body_Id, Is_Compilation_Unit (Spec_Id));
+         Set_Is_Child_Unit       (Body_Id, Is_Child_Unit       (Spec_Id));
 
-            Analyze_Generic_Subprogram_Body (N, Spec_Id);
+         Analyze_Generic_Subprogram_Body (N, Spec_Id);
 
-            if Nkind (N) = N_Subprogram_Body then
-               Check_Missing_Return;
-            end if;
+         if Nkind (N) = N_Subprogram_Body then
+            Check_Missing_Return;
+         end if;
 
-            goto Leave;
+         goto Leave;
 
-         --  Otherwise a previous entity conflicts with the subprogram name.
-         --  Attempting to enter name will post error.
+      --  If the subprogram body is defined within an instance of the same
+      --  name, the instance appears as a package renaming, and will be hidden
+      --  within the subprogram. Otherwise a previous non-overloadable entity
+      --  conflicts with the subprogram. Entering the name will post an error.
 
-         else
-            Enter_Name (Body_Id);
-            goto Leave;
-         end if;
+      elsif Present (Prev_Id)
+        and then not Is_Overloadable (Prev_Id)
+        and then (Nkind (Parent (Prev_Id)) /= N_Package_Renaming_Declaration
+                   or else Comes_From_Source (Prev_Id))
+      then
+         Enter_Name (Body_Id);
+         goto Leave;
 
       --  Non-generic case, find the subprogram declaration, if one was seen,
-      --  or enter new overloaded entity in the current scope. If the
+      --  or else enter a new overloaded entity in the current scope. If the
       --  Current_Entity is the Body_Id itself, the unit is being analyzed as
       --  part of the context of one of its subunits. No need to redo the
       --  analysis.