public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Fix binding of ghost units with finalizer
@ 2019-07-23  8:13 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2019-07-23  8:13 UTC (permalink / raw)
  To: gcc-patches; +Cc: Yannick Moy

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

Linking of an enabled ghost unit which requires a finalizer lead to an
error, as the name generated by the binder for calling the finalizer was
not the same as the name chosen by the compiler. Now fixed.

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

2019-07-23  Yannick Moy  <moy@adacore.com>

gcc/ada/

	* exp_ch7.adb (Create_Finalizer): Force finalizer not to be
	Ghost enabled.
	* exp_dbug.adb (Get_External_Name): Explain special case of
	Ghost finalizer.

gcc/testsuite/

	* gnat.dg/ghost6.adb, gnat.dg/ghost6_pkg.ads: New testcase.

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

--- gcc/ada/exp_ch7.adb
+++ gcc/ada/exp_ch7.adb
@@ -2035,6 +2035,13 @@ package body Exp_Ch7 is
 
             Analyze (Fin_Body, Suppress => All_Checks);
          end if;
+
+         --  Never consider that the finalizer procedure is enabled Ghost, even
+         --  when the corresponding unit is Ghost, as this would lead to an
+         --  an external name with a ___ghost_ prefix that the binder cannot
+         --  generate, as it has no knowledge of the Ghost status of units.
+
+         Set_Is_Checked_Ghost_Entity (Fin_Id, False);
       end Create_Finalizer;
 
       --------------------------

--- gcc/ada/exp_dbug.adb
+++ gcc/ada/exp_dbug.adb
@@ -914,6 +914,14 @@ package body Exp_Dbug is
       --  names produced for Ghost entities, while "__ghost_" can appear in
       --  names of entities inside a child/local package called "Ghost".
 
+      --  The compiler-generated finalizer for an enabled Ghost unit is treated
+      --  specially, as its name must be known to the binder, which has no
+      --  knowledge of Ghost status. In that case, the finalizer is not marked
+      --  as Ghost so that no prefix is added. Note that the special ___ghost_
+      --  prefix is retained when the Ghost unit is ignored, which still allows
+      --  inspecting the final executable for the presence of an ignored Ghost
+      --  finalizer procedure.
+
       if Is_Ghost_Entity (E)
         and then not Is_Compilation_Unit (E)
         and then (Name_Len < 9

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/ghost6.adb
@@ -0,0 +1,10 @@
+--  { dg-do link }
+--  { dg-options "-gnata -g" }
+
+with Ghost6_Pkg;
+
+procedure Ghost6 is
+   X : Ghost6_Pkg.T with Ghost;
+begin
+   null;
+end Ghost6;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/ghost6_pkg.ads
@@ -0,0 +1,7 @@
+with Ada.Finalization;
+
+package Ghost6_Pkg with
+  Ghost
+is
+   type T is new Ada.Finalization.Controlled with null record;
+end Ghost6_Pkg;


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

only message in thread, other threads:[~2019-07-23  8:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-23  8:13 [Ada] Fix binding of ghost units with finalizer 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).