From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id A0B0D385627A for ; Mon, 9 May 2022 09:30:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A0B0D385627A Received: by mail-wm1-x329.google.com with SMTP id a14-20020a7bc1ce000000b00393fb52a386so10415781wmj.1 for ; Mon, 09 May 2022 02:30:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=ZbTl5a+i8TwICuyknVPHXeKhncc2Gnp+nXgHC9peCac=; b=vALD1KghnWJX/wjK1iA2BxWf6nsIR4E7pdJkhZYOafczU3KbP7EpmRKeITqCRFAI0e O2stoXQMR1C40uGtGTnm1LvNt/CH8hKmS6zMIfz9gIpK51UE9Cj6BHTxlP6scYD9jgvx 2cgfgKRMX4wAJh4Pkoz76AaFNNnG6sScDnePK5nhSx8KF0awW61hkk7oDoR5hKaqEQWc MSaPerJlR1PUbl7CFIht9uUubglAJCjbFJpzQ7k8WJzKN7n6k92G1/bEvAMgKl/MPhHJ BnF4sJ1nsAVobdLFWewZrAt46afmlweBLKGte4jnUIFdiVogtX78VRwTeBhxSKvS0UHP ygjg== X-Gm-Message-State: AOAM533boso9wNj2/vbuyKk6DGXFMaS1WPQ2dmjb9xYGUq0t97+JMMVk /RqKsvXCWTh4/H58WdnUcep0PYDeYH8cAw== X-Google-Smtp-Source: ABdhPJxczLM+oa8+Wo7+OPU6sg/aMSIiut48dJYLAsd34UKCegBIoNqMa3EOpwVWzoNegJtROgtCDg== X-Received: by 2002:a05:600c:354e:b0:394:89ba:e211 with SMTP id i14-20020a05600c354e00b0039489bae211mr6580923wmq.86.1652088626476; Mon, 09 May 2022 02:30:26 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id p6-20020a05600c358600b0039429bfebeasm23749829wmq.2.2022.05.09.02.30.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 02:30:25 -0700 (PDT) Date: Mon, 9 May 2022 09:30:25 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Fix package installation for private array type of private element Message-ID: <20220509093025.GA3184353@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="cNdxnHkX5QqsyA0e" Content-Disposition: inline X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 May 2022 09:30:29 -0000 --cNdxnHkX5QqsyA0e Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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. --cNdxnHkX5QqsyA0e Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" 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; --cNdxnHkX5QqsyA0e--