public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Fix package installation for private array type of private element
@ 2022-05-09  9:30 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2022-05-09  9:30 UTC (permalink / raw)
  To: gcc-patches; +Cc: Ed Schonberg

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

The problem comes from the construction of Stream operations, which
happens at the point a tagged type is frozen. Streams need to see the
full view of types, so that for example the Read attribute for an array
can be expanded into a loop over the Read attribute for the component
type.  Now if during that expansion we have a private type we may need
to retrieve the full view of the type to find its structure. And the
corresponding tree must be compiled in the context of the package that
defines the type, which might not be the current package.  The problem
arises when both array and component types are private, then the
described mechanism is invoked twice.

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

gcc/ada/

	* exp_attr.adb (Compile_Stream_Body_In_Scope): Do not install
	package if array type and element type come from the same
	package, and the original array type is private.

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

diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb
--- a/gcc/ada/exp_attr.adb
+++ b/gcc/ada/exp_attr.adb
@@ -888,6 +888,11 @@ package body Exp_Attr is
          --  special stream-processing operations for that type (for example
          --  Unbounded_String and its wide varieties).
 
+         --  We don't install the package either if array type and element
+         --  type come from the same package, and the original array type is
+         --  private, because in this case the underlying type Arr is
+         --  itself a full view, which carries the full view of the component.
+
          Scop := Scope (C_Type);
 
          if Is_Private_Type (C_Type)
@@ -896,7 +901,15 @@ package body Exp_Attr is
            and then Ekind (Scop) = E_Package
            and then No (Get_Stream_Convert_Pragma (C_Type))
          then
-            Install := True;
+            if Scope (Arr) = Scope (C_Type)
+              and then Is_Private_Type (Etype (Prefix (N)))
+              and then Full_View (Etype (Prefix (N))) = Arr
+            then
+               null;
+
+            else
+               Install := True;
+            end if;
          end if;
       end if;
 



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

only message in thread, other threads:[~2022-05-09  9:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-09  9:30 [Ada] Fix package installation for private array type of private element 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).