public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Fix issues with ignored ghost code and unnesting
@ 2021-12-01 10:25 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-12-01 10:25 UTC (permalink / raw)
  To: gcc-patches; +Cc: Richard Kenner

[-- Attachment #1: Type: text/plain, Size: 482 bytes --]

Unnesting needs to be run after all ignored ghost code is removed
so that it doesn't try to put entities into activation records that will
be removed. Also, don't add subprograms that are ignored into the list
of inlined subprograms.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* frontend.adb (Frontend): Do unnesting after ignored ghost code
	has been removed.
	* inline.adb (Analyze_Inlined_Bodies): Don't put ignored ghost
	entities on inlined subprogram list.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1995 bytes --]

diff --git a/gcc/ada/frontend.adb b/gcc/ada/frontend.adb
--- a/gcc/ada/frontend.adb
+++ b/gcc/ada/frontend.adb
@@ -473,12 +473,6 @@ begin
                Check_Elaboration_Scenarios;
             end if;
 
-            --  At this stage we can unnest subprogram bodies if required
-
-            if Total_Errors_Detected = 0 then
-               Exp_Unst.Unnest_Subprograms (Cunit (Main_Unit));
-            end if;
-
             --  List library units if requested
 
             if List_Units then
@@ -494,12 +488,19 @@ begin
             Sem_Warn.Output_Unused_Warnings_Off_Warnings;
 
             --  Remove any ignored Ghost code as it must not appear in the
-            --  executable. This action must be performed last because it
+            --  executable. This action must be performed very late because it
             --  heavily alters the tree.
 
             if Operating_Mode = Generate_Code or else GNATprove_Mode then
                Remove_Ignored_Ghost_Code;
             end if;
+
+            --  At this stage we can unnest subprogram bodies if required
+
+            if Total_Errors_Detected = 0 then
+               Exp_Unst.Unnest_Subprograms (Cunit (Main_Unit));
+            end if;
+
          end if;
       end if;
    end;


diff --git a/gcc/ada/inline.adb b/gcc/ada/inline.adb
--- a/gcc/ada/inline.adb
+++ b/gcc/ada/inline.adb
@@ -1087,9 +1087,14 @@ package body Inline is
          --  subprograms for the unit.
 
          for Index in Inlined.First .. Inlined.Last loop
-            if Is_Called (Inlined.Table (Index).Name) then
-               Add_Inlined_Subprogram (Inlined.Table (Index).Name);
-            end if;
+            declare
+               E : constant Subprogram_Kind_Id := Inlined.Table (Index).Name;
+
+            begin
+               if Is_Called (E) and then not Is_Ignored_Ghost_Entity (E) then
+                  Add_Inlined_Subprogram (E);
+               end if;
+            end;
          end loop;
 
          Pop_Scope;



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-12-01 10:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-01 10:25 [Ada] Fix issues with ignored ghost code and unnesting Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).