public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <pmderodat@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-188] [Ada] Fix package installation for private array type of private element
Date: Mon,  9 May 2022 09:31:25 +0000 (GMT)	[thread overview]
Message-ID: <20220509093125.174313858427@sourceware.org> (raw)

https://gcc.gnu.org/g:09cca56d660042991a7267b568641e16e77d0ba1

commit r13-188-g09cca56d660042991a7267b568641e16e77d0ba1
Author: Ed Schonberg <schonberg@adacore.com>
Date:   Wed Jan 12 12:04:58 2022 +0100

    [Ada] Fix package installation for private array type of private element
    
    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.
    
    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.

Diff:
---
 gcc/ada/exp_attr.adb | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb
index 5374dd4d7e9..ab14a498117 100644
--- 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;


                 reply	other threads:[~2022-05-09  9:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220509093125.174313858427@sourceware.org \
    --to=pmderodat@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).