public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Ada ABI change when building with assertions
@ 2022-05-13  8:07 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2022-05-13  8:07 UTC (permalink / raw)
  To: gcc-patches; +Cc: Javier Miranda

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

Compiling with and without assertions enabled the name of some generated
symbols differ; this is an issue when using pre-built libraries.

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

gcc/ada/

	* freeze.adb (Check_Inherited_Conditions): Dispatch table
	wrappers must be placed in the list of entities of their scope
	at the same place of their wrapped primitive. This is required
	for private types since these wrappers are built when their full
	tagged type declaration is frozen but they may override a
	primitive defined in the public part of the package (and it is
	important to maintain the wrapper in the list of public entities
	of the package to ensure their correct visibility).

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

diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -1981,6 +1981,9 @@ package body Freeze is
                DTW_Id   : Entity_Id;
                DTW_Spec : Node_Id;
 
+               Prim_Next_E : constant Entity_Id := Next_Entity (Prim);
+               Prim_Prev_E : constant Entity_Id := Prev_Entity (Prim);
+
             begin
                --  The wrapper must be analyzed in the scope of its wrapped
                --  primitive (to ensure its correct decoration).
@@ -2049,9 +2052,46 @@ package body Freeze is
                   Insert_Before_And_Analyze (Freeze_Node (R), DTW_Decl);
                else
                   Append_Freeze_Action (R, DTW_Decl);
+                  Analyze (DTW_Decl);
                end if;
 
-               Analyze (DTW_Decl);
+               --  The analyis of DTW_Decl has removed Prim from its scope
+               --  chain and added DTW_Id at the end of the scope chain. Move
+               --  DTW_Id to its correct place in the scope chain: the analysis
+               --  of the wrapper declaration has just added DTW_Id at the end
+               --  of the list of entities of its scope. However, given that
+               --  this wrapper overrides Prim, we must move DTW_Id to the
+               --  original place of Prim in its scope chain. This is required
+               --  for wrappers of private type primitives to ensure their
+               --  correct visibility since wrappers are built when the full
+               --  tagged type declaration is frozen (in the private part of
+               --  the package) but they may override primitives defined in the
+               --  public part of the package.
+
+               declare
+                  DTW_Prev_E : constant Entity_Id := Prev_Entity (DTW_Id);
+
+               begin
+                  pragma Assert (Last_Entity (Current_Scope) = DTW_Id);
+                  pragma Assert
+                    (Ekind (Current_Scope) not in E_Package | E_Generic_Package
+                       or else No (First_Private_Entity (Current_Scope))
+                       or else First_Private_Entity (Current_Scope) /= DTW_Id);
+
+                  --  Remove DTW_Id from the end of the doubly-linked list of
+                  --  entities of this scope; no need to handle removing it
+                  --  from the beginning of the chain since such case can never
+                  --  occur for this entity.
+
+                  Set_Last_Entity (Current_Scope, DTW_Prev_E);
+                  Set_Next_Entity (DTW_Prev_E, Empty);
+
+                  --  Place DTW_Id back in the original place of its wrapped
+                  --  primitive in the list of entities of this scope.
+
+                  Link_Entities (Prim_Prev_E, DTW_Id);
+                  Link_Entities (DTW_Id, Prim_Next_E);
+               end;
 
                --  Insert the body of the wrapper in the freeze actions of
                --  its record type declaration to ensure that it is placed



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

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

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-13  8:07 [Ada] Ada ABI change when building with assertions 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).