From patchwork Tue Jun 27 12:08:01 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: 113384 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8144474vqr; Tue, 27 Jun 2023 05:09:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ64H19QlDjtJUJ8jARcyDoaJfxmrbBEuptVWua83Wljv2y+jEyM+ttHeNidcPZe1E5c7JBX X-Received: by 2002:a05:6512:3487:b0:4fb:820a:f87f with SMTP id v7-20020a056512348700b004fb820af87fmr1315461lfr.10.1687867796731; Tue, 27 Jun 2023 05:09:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687867796; cv=none; d=google.com; s=arc-20160816; b=cbECf6FGl2Dccz3yHTlkM+Q7vFxqGwDNml6C6zxYvABu9mGkDnqptWpoiN2AudRV15 yD1CoV06ScAfPvfO0nzgk1W+POOz5XcwLwexpKyz/E8BcWcDr7t9n7ab29VnUF18ZaK9 dpQmMvN3s23hyXUB0VkYUUYnZnRzSav4BRX8ls+32/s+dYkPU20AU4NIGjsBcc/zIijB gIOKmb8XRLBqIheqn5k2rkkD/FBmadSk1lkOi3Hxv2pn8Ve1IcJNQ2SUXenHa53J07pg 7bokt0svCnZSA7yjdwOnFSYjWokG+/GKSYqPhKcCWCUq6ZdN223yr0CWvswQ/AWYO9As yfdQ== 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=rJD8BjMWuI6PohQ+yfvO3eD8tRuMtSP29DtFe1dV008=; fh=hOhsC1930eHatDPYd2EALQ9Ry/g++vvN4vxlQkRuX+0=; b=xTfKn7nYn66Rwo5oOZ/oW85Pzw2EVSCy0B81vxDv8LA+64Hegvw+t2KaiETnyYG/5h ufgH8g74fzgCQ9tEzG8SHlxBFtwMNuGcpnUGri/t4CcC0/69Szz7l+UKOZjJPBN9ZfbV tfiDZo2v31ZPOUHXMqixv8xNFHUEwwt/L9ROc0qtE/k0D1bW4g3fxVl/HcHQHj8NQ7Ik ymKsSPjxUtZiK3D7tuLJxpCopflo9AYql4cpczVBjjYJvizQ+V0hcOJkB/63wHHWhsGk 51Rg0DMkx99eTInzgv+1gnsdbE2ZwsuQLWVnbYES2oDQEwW6vSh6PWD9Y0ry5OPpB6KI VyZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=J8Qf0Yhe; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id e2-20020a50fb82000000b0051d8a5bca6csi3366443edq.680.2023.06.27.05.09.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 05:09:56 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=J8Qf0Yhe; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 3231B385084C for ; Tue, 27 Jun 2023 12:08:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3231B385084C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687867736; bh=rJD8BjMWuI6PohQ+yfvO3eD8tRuMtSP29DtFe1dV008=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=J8Qf0Yhe2aWsPXAs9PUxfmKJuteB75m6tS+l8X9yGaG/5v5BD+b1VWx8uOsZSzyuV kzOhy1x48pp4t4MtNI/R6vv9MesMS4IIb/OBl+K2zajfQlFkWnXDdBbYrDbvL6taRT GBhYgS/NLR/vDx2SVs+abjj5dHgwNOUfZN5uiu7c= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by sourceware.org (Postfix) with ESMTPS id 19BB53858414 for ; Tue, 27 Jun 2023 12:08:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 19BB53858414 Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2b6a152a933so33225341fa.1 for ; Tue, 27 Jun 2023 05:08:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687867683; x=1690459683; 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=rJD8BjMWuI6PohQ+yfvO3eD8tRuMtSP29DtFe1dV008=; b=RxYysm+NN1hyTaH1ouKBcxNt/AYoaKASz1eXE1jULGVQkWUIIt00rh92Xjn20e/2B4 /xBmhyyK+XqzicIZK9DBslqCBvZDXegBPLtdRdaVE2BFh9aALT8xJRCZEcL+CnrmfuP8 3SLAhgDILHRP9TGSSIlZ0F7fq/T33Dmqr34NTLeL92KIlCQCG3W0wNqToOXekrZm4lCq oZCgJjVTnhhrjQYuNKBTmgA2lpL2N25JK/7gGGdLrfwUdXb15fTX9MArkjePbohJb7Zg LvSCiL98lV9ZiP8vE+W82yiwIChVxFxGFo16SDkPv+rEMO5NgqNx55dms7LBvChpz+n6 OIKA== X-Gm-Message-State: AC+VfDz0tQdj0vvWojJOGEJ0uWtEjaarIVZakFVX7neT+yXZDo8U9TfS mrXBNVnQMH/cETJw850QL+zElgoorY2I2f0EMjXC0A== X-Received: by 2002:ac2:4bd0:0:b0:4fb:b11:c99d with SMTP id o16-20020ac24bd0000000b004fb0b11c99dmr4528221lfq.57.1687867683283; Tue, 27 Jun 2023 05:08:03 -0700 (PDT) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id f7-20020a1c6a07000000b003fb5e3710d3sm2647265wmc.43.2023.06.27.05.08.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 05:08:02 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Plug small loophole in the handling of private views in instances Date: Tue, 27 Jun 2023 14:08:01 +0200 Message-Id: <20230627120801.3419890-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 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.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.29 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769857662979876666?= X-GMAIL-MSGID: =?utf-8?q?1769857662979876666?= From: Eric Botcazou This deals with nested instantiations in package bodies. gcc/ada/ * sem_ch12.adb (Scope_Within_Body_Or_Same): New predicate. (Check_Actual_Type): Take into account packages nested in bodies to compute the enclosing scope by means of Scope_Within_Body_Or_Same. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_ch12.adb | 46 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb index fbfc2db7f9a..43fcff2c9d5 100644 --- a/gcc/ada/sem_ch12.adb +++ b/gcc/ada/sem_ch12.adb @@ -7001,11 +7001,11 @@ package body Sem_Ch12 is -- The enclosing scope of the generic unit procedure Check_Actual_Type (Typ : Entity_Id); - -- If the type of the actual is a private type declared in the - -- enclosing scope of the generic unit, but not a derived type - -- of a private type declared elsewhere, the body of the generic - -- sees the full view of the type (because it has to appear in - -- the corresponding package body). If the type is private now, + -- If the type of the actual is a private type declared in the enclosing + -- scope of the generic, either directly or through packages nested in + -- bodies, but not a derived type of a private type declared elsewhere, + -- then the body of the generic sees the full view of the type because + -- it has to appear in the package body. If the type is private now then -- exchange views to restore the proper visibility in the instance. ----------------------- @@ -7015,16 +7015,48 @@ package body Sem_Ch12 is procedure Check_Actual_Type (Typ : Entity_Id) is Btyp : constant Entity_Id := Base_Type (Typ); + function Scope_Within_Body_Or_Same + (Inner : Entity_Id; + Outer : Entity_Id) return Boolean; + -- Determine whether scope Inner is within the body of scope Outer + -- or is Outer itself. + + ------------------------------- + -- Scope_Within_Body_Or_Same -- + ------------------------------- + + function Scope_Within_Body_Or_Same + (Inner : Entity_Id; + Outer : Entity_Id) return Boolean + is + Curr : Entity_Id := Inner; + + begin + while Curr /= Standard_Standard loop + if Curr = Outer then + return True; + + elsif Is_Package_Body_Entity (Curr) then + Curr := Scope (Curr); + + else + exit; + end if; + end loop; + + return False; + end Scope_Within_Body_Or_Same; + begin -- The exchange is only needed if the generic is defined -- within a package which is not a common ancestor of the -- scope of the instance, and is not already in scope. if Is_Private_Type (Btyp) - and then Scope (Btyp) = Parent_Scope and then not Has_Private_Ancestor (Btyp) and then Ekind (Parent_Scope) in E_Package | E_Generic_Package - and then Scope (Instance) /= Parent_Scope + and then Scope_Within_Body_Or_Same (Parent_Scope, Scope (Btyp)) + and then Parent_Scope /= Scope (Instance) and then not Is_Child_Unit (Gen_Id) then Switch_View (Btyp);