From patchwork Tue Sep 5 11:08:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 137511 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp1609427vqo; Tue, 5 Sep 2023 04:17:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGcbPcOEm5Ww+Li11YkimQ3EzGQd6AgLopTfNTxxj2cd80mI7n1sfnSp7uyY9WMDDKPjHVn X-Received: by 2002:a17:906:257:b0:9a5:b8ca:9b76 with SMTP id 23-20020a170906025700b009a5b8ca9b76mr7714928ejl.72.1693912670091; Tue, 05 Sep 2023 04:17:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693912670; cv=none; d=google.com; s=arc-20160816; b=zS0UAuSr+ZSpV56QsJ6VwpAdY4/Mti74/pRA3rR9+SXXVfX9Wd9SkaVq+jMofoZj+z R5YdwvXoDkI1lIxu68wDhYnxeu009YLjmFL3jp/zI3DsJCPGuZgX2qtfP5brlz0HrVH9 0b/uSfbmWbJZaiWFCXu+1fopGXZ48FhzHmZCjFZou8Kp4cJZYNiPLxG5OBmkof9sWCFv p5jVS5jCnMCTVktXwE2PnvSGUTXPp7CiE/cAh3Jz8wqNeM83EwLj/m91DHxzVovTulrI osGftRkrBaTuXfqdQcg9NA04ZW5J/s6KV852otHrYnMZjuMWDlQGj0Arw0VLiHbSNb+4 FdXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=bhum5hZBsVtCyrATs0gO4bbBxQ3Cgt/vB12b7Zg2kDk=; fh=hOhsC1930eHatDPYd2EALQ9Ry/g++vvN4vxlQkRuX+0=; b=Qn2CGwWdPQy7aqThoESmnIKX42hkXPMCZWzZHb2s6cqy0whHQ7sBn/AO6mr0BNrEr8 2rHg9AN/6gFmt4Jfz4ZGBPanxDl57wbp2W9alflZa0FK49Wkh908rOaijF8uL+lu7PAg NKITSqGMqV5B9tcFr7z+VJrk0EeaYBabN4yNSHeRBLTFcghBpPK/tY+gpuRwgf9VOaZO D0jcp6s+TY7dywsV5g2dKiR0h+Z45z+DqelRAX3eUIFrhGMjwkNy/QNrKRnCRAdkzIWL BW1zT6xjXVS59MEOwjvbUcAZwL3IVUgBvxdNT2eQt1U7BVN6QGH/Ur+UVGx6Kj/e7+UN aUSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=KfFaea4y; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id pj9-20020a170906d78900b009931472bdb8si7177339ejb.965.2023.09.05.04.17.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Sep 2023 04:17:50 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=KfFaea4y; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A1C3D3952000 for ; Tue, 5 Sep 2023 11:11:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A1C3D3952000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1693912312; bh=bhum5hZBsVtCyrATs0gO4bbBxQ3Cgt/vB12b7Zg2kDk=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=KfFaea4ysbTG0T/Blemgo0op8p1o0P0KpjVOoPacwEA967kRw5ooVfyfAkaGw8tw1 cLbi9ueqEXFy7lmsIrDF8/WlFCy1UDNn7UvS9XOFcaw/CH3fA2keplwXSS1V+TmHMg +A4Y3k3TUM6fycp5TMJvT0YOncZ5K+T12uAP/bWU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by sourceware.org (Postfix) with ESMTPS id 1580C385701D for ; Tue, 5 Sep 2023 11:08:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1580C385701D Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2bbbda48904so38887231fa.2 for ; Tue, 05 Sep 2023 04:08:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693912083; x=1694516883; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=bhum5hZBsVtCyrATs0gO4bbBxQ3Cgt/vB12b7Zg2kDk=; b=PzkgsnHAhlh918Pp68x6B2hxc+Vx947jhLQvdU7XJ5P9Ui596BRCBKllz9sPGE3Lj6 tu/fWtl1JnCAYrm9pE5oqr1g5kMbtla+mt6WATcl6bC5i2oTTG+aoGLMr524yM41GoH1 jbX+el2LAhTraBCSD0afqdjtDuozjSFCYna9crYzdPvsdQY1mVlkua5tsa3XKyOJuOND MwVhC92THISDStEHoezhfX4LqXNTeHtcG9iTMbA3MRrngcwXLuY7XrUerFK1uFhVuIj6 IuJzCLseW/V5chf8u/lXhbiiCAXSFTYS9oK8Jkk/ZufwucZbZL/i+8yIqtWTaI9fm/IH FE8w== X-Gm-Message-State: AOJu0Ywh5LmC65eyQWm4KPDvhqzEecsYKt7tj/UPW/8qbTbeEjQ84iA6 Ifn4dYen+gT2Uk77xHMlHOIx8P94QFyBpsaTO34dSQ== X-Received: by 2002:a2e:9082:0:b0:2b9:b693:c906 with SMTP id l2-20020a2e9082000000b002b9b693c906mr8301080ljg.27.1693912083569; Tue, 05 Sep 2023 04:08:03 -0700 (PDT) Received: from poulhies-Precision-5550.lan ([2001:861:3382:1a90:20fc:79e4:455c:1075]) by smtp.gmail.com with ESMTPSA id l4-20020a5d4804000000b0031c56218984sm17031260wrq.104.2023.09.05.04.08.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Sep 2023 04:08:02 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Fix internal error on instantiation with private component type Date: Tue, 5 Sep 2023 13:08:02 +0200 Message-Id: <20230905110802.562452-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776196171628405494 X-GMAIL-MSGID: 1776196171628405494 From: Eric Botcazou First, this fixes an internal error on the instantiation of a nested generic package taking an array type whose component type is a private type declared in the parent package as formal type parameter. In the body of the instance, the full view of the private type is visible and must be restored by means of the Check_Generic_Actuals mechanism. Second, this fixes the same internal error in the case where the component type itself is an array type whose component type is a private type declared in the parent package, i.e. when the formal type parameter is an array of array type, by naturally extending the Has_Secondary_Private_View mechanism to the array of array case. gcc/ada/ * sem_ch12.adb (Component_Type_For_Private_View): New function. (Check_Generic_Actuals): For an actual type parameter, also check its component type if it is an array type. (Check_Private_View): Use Component_Type_For_Private_View in the case of an array type. (Instantiate_Type): Likewise. (Save_Global_References.Set_Global_Type): Likewise. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_ch12.adb | 54 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb index 61e0ec47392..c264f2a8283 100644 --- a/gcc/ada/sem_ch12.adb +++ b/gcc/ada/sem_ch12.adb @@ -582,6 +582,13 @@ package body Sem_Ch12 is -- Recurse on an actual that is a formal package whose declaration has -- a box. + function Component_Type_For_Private_View (T : Entity_Id) return Entity_Id; + -- Return the component type of array type T, with the following addition: + -- if this component type itself is an array type which has not been first + -- declared as private, then recurse on it. This makes it possible to deal + -- with arrays of arrays the same way as multi-dimensional arrays in the + -- mechanism handling private views. + function Contains_Instance_Of (Inner : Entity_Id; Outer : Entity_Id; @@ -7084,10 +7091,27 @@ package body Sem_Ch12 is and then Scope (Etype (E)) /= Instance and then Is_Entity_Name (Subtype_Indication (Parent (E))) then - -- Restore the proper view of the actual from the information - -- saved earlier by Instantiate_Type. + declare + Indic : constant Node_Id := Subtype_Indication (Parent (E)); + + begin + -- Restore the proper view of the actual from the information + -- saved earlier by Instantiate_Type. + + Check_Private_View (Indic); - Check_Private_View (Subtype_Indication (Parent (E))); + -- If this view is an array type, check its component type. + -- This handles the case of an array type whose component + -- type is private, used as the actual in an instantiation + -- of a generic construct declared in the same package as + -- the component type and taking an array type with this + -- component type as formal type parameter. + + if Is_Array_Type (Etype (Indic)) then + Check_Actual_Type + (Component_Type_For_Private_View (Etype (Indic))); + end if; + end; -- If the actual is itself the formal of a parent instance, -- then also restore the proper view of its actual and so on. @@ -7759,7 +7783,8 @@ package body Sem_Ch12 is elsif Is_Array_Type (Typ) then Check_Private_Type - (Component_Type (Typ), Has_Secondary_Private_View (N)); + (Component_Type_For_Private_View (Typ), + Has_Secondary_Private_View (N)); elsif (Is_Record_Type (Typ) or else Is_Concurrent_Type (Typ)) and then Has_Discriminants (Typ) @@ -7821,6 +7846,21 @@ package body Sem_Ch12 is return Result; end Check_Hidden_Primitives; + ------------------------------------- + -- Component_Type_For_Private_View -- + ------------------------------------- + + function Component_Type_For_Private_View (T : Entity_Id) return Entity_Id is + Typ : constant Entity_Id := Component_Type (T); + + begin + if Is_Array_Type (Typ) and then not Has_Private_Declaration (Typ) then + return Component_Type_For_Private_View (Typ); + else + return Typ; + end if; + end Component_Type_For_Private_View; + -------------------------- -- Contains_Instance_Of -- -------------------------- @@ -14373,7 +14413,8 @@ package body Sem_Ch12 is elsif (Is_Access_Type (Act_T) and then Is_Private_Type (Designated_Type (Act_T))) or else (Is_Array_Type (Act_T) - and then Is_Private_Type (Component_Type (Act_T))) + and then + Is_Private_Type (Component_Type_For_Private_View (Act_T))) then Set_Has_Secondary_Private_View (Subtype_Indication (Decl_Node)); end if; @@ -16899,7 +16940,8 @@ package body Sem_Ch12 is if (Is_Access_Type (Typ) and then Is_Private_Type (Designated_Type (Typ))) or else (Is_Array_Type (Typ) - and then Is_Private_Type (Component_Type (Typ))) + and then + Is_Private_Type (Component_Type_For_Private_View (Typ))) then Set_Has_Secondary_Private_View (N); end if;