]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Small cleanup in instantiation of generic bodies
authorEric Botcazou <ebotcazou@adacore.com>
Thu, 27 Mar 2025 12:27:46 +0000 (13:27 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 10 Jun 2025 07:32:09 +0000 (09:32 +0200)
This removes the code dealing with generic main units from the body of the
instantiation routine, namely Instantiate_Bodies, and replaces it by tests
done earlier in the processing.

The test added to Need_Subprogram_Instance_Body is already present in the
twin predicate Needs_Body_Instantiated.

gcc/ada/ChangeLog:

* inline.adb (Instantiate_Body): Do not call Add_Scope_To_Clean if
the main unit is generic.
(Instantiate_Bodies): Do not deal with generic main units here.
* sem_ch12.adb (Need_Subprogram_Instance_Body): Return false if the
main unit is generic.

gcc/ada/inline.adb
gcc/ada/sem_ch12.adb

index abb49b51e6308832c14dd51c2678fecb27eb9e7e..0e6cf4df3b7254b95cceb63c10b9c998102c6cfd 100644 (file)
@@ -4924,11 +4924,17 @@ package body Inline is
               and then Ekind (Info.Fin_Scop) = E_Package_Body
             then
                Set_In_Package_Body (Spec_Entity (Info.Fin_Scop), True);
+               Instantiate_Package_Body (Info);
+               Set_In_Package_Body (Spec_Entity (Info.Fin_Scop), False);
+            else
+               Instantiate_Package_Body (Info);
             end if;
 
-            Instantiate_Package_Body (Info);
+            --  No need to generate cleanups if the main unit is generic
 
-            if Present (Info.Fin_Scop) then
+            if Present (Info.Fin_Scop)
+               and then not Is_Generic_Unit (Main_Unit_Entity)
+            then
                Scop := Info.Fin_Scop;
 
                --  If the enclosing finalization scope is dynamic, the instance
@@ -4941,12 +4947,6 @@ package body Inline is
                end if;
 
                Add_Scope_To_Clean (Scop);
-
-               --  Reset the In_Package_Body flag if it was set above
-
-               if Ekind (Info.Fin_Scop) = E_Package_Body then
-                  Set_In_Package_Body (Spec_Entity (Info.Fin_Scop), False);
-               end if;
             end if;
 
          --  For subprogram instances, always instantiate the body
@@ -4967,10 +4967,6 @@ package body Inline is
          Push_Scope (Standard_Standard);
          To_Clean := New_Elmt_List;
 
-         if Is_Generic_Unit (Cunit_Entity (Main_Unit)) then
-            Start_Generic;
-         end if;
-
          --  A body instantiation may generate additional instantiations, so
          --  the following loop must scan to the end of a possibly expanding
          --  set (that's why we cannot simply use a FOR loop here). We must
@@ -5009,16 +5005,10 @@ package body Inline is
             Pending_Instantiations.Init;
          end if;
 
-         --  We can now complete the cleanup actions of scopes that contain
-         --  pending instantiations (skipped for generic units, since we
-         --  never need any cleanups in generic units).
+         --  Expand the cleanup actions of scopes that contain instantiations
 
-         if Expander_Active
-           and then not Is_Generic_Unit (Main_Unit_Entity)
-         then
+         if Expander_Active then
             Cleanup_Scopes;
-         elsif Is_Generic_Unit (Cunit_Entity (Main_Unit)) then
-            End_Generic;
          end if;
 
          Pop_Scope;
index 017bcba42ef6a613889b60f75146fdfdc63fba00..1d947806336962f2b131b1b4f4373b2f209d8880 100644 (file)
@@ -6032,6 +6032,10 @@ package body Sem_Ch12 is
 
       if (Is_In_Main_Unit (N) or else Is_Inlined_Or_Child_Of_Inlined (Subp))
 
+        --  No need to instantiate bodies in generic units
+
+        and then not Is_Generic_Unit (Cunit_Entity (Main_Unit))
+
         --  Must be generating code or analyzing code in GNATprove mode
 
         and then (Operating_Mode = Generate_Code