From patchwork Mon May 29 08:29:04 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: 100148 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1362724vqr; Mon, 29 May 2023 01:35:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4L8Lwp87xqRrcxwpewqBawnKO/3HbKWATOMxxgn0z2HXWcNyC3NZ1GE85jDYYNM4TsLDjd X-Received: by 2002:a17:907:7b98:b0:947:335f:5a0d with SMTP id ne24-20020a1709077b9800b00947335f5a0dmr10799630ejc.62.1685349354729; Mon, 29 May 2023 01:35:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685349354; cv=none; d=google.com; s=arc-20160816; b=JbgRX9CchvcLqMxEYFyJTJ3ETu7F+nofbWHBlIjYf0btk1Skh/sO4QpxNG8HY7eCzV rXuShv6SMJhxZ+w0MG890i37n4ts2u9yNibGEfAYAibtbDzdQaeyFFUBftSB72c1nSXj nWBdEy73eXuULmNzZS1N7UIM0KMQ0ge4fa16VkNw1PmpJsQ3g1gx6kaWLeJN3/gMnLZD S1pTlipYr3LleZ9k99AbJ5TIlSsqgHlIpRgW50g5waI6WAnocA9BRkmaEp/mfhgDq4qW o5NhdRQF+BkbjO8zxjgmk6PrzfZglTN4EP+XXu2q3sF4BgdToAOak5No8rgHUW5zzusU Zclg== 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=A6TLcVHgwKWDoDqVbLV0pMXh4IMZght+sL8gojeHLFY=; b=WTm58GYUnI4iuCadaRFSsYY0iIemA9vg7cc4/s+B83MbI1ALJ7nIIApQkjkPSDJUXk OzOqIOJITxOsHQ8Q/cb/3zKDo85wYllW3tstGFqtxq4r6dRSZPQ9P5I7FEEpMh40tzjD MrxyXd249vjsxlwXL2+wjnHudOZX0GUewybxdFCimWEHikp9joK660oC4c0rKzcKbl+t 1N2nKhaSxBmhhz23aSi3K4Es/zcettT8g9c64aDCis7qKpasuYtMIM2txNseE2gOChxc 2nvLoLTcdFb3Dj7AmpWSXb3j/HQlV4wolNKAXS7jlfMB+xdiII/pnIBbdlFLikJLBTfY Nu+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=v76ZnpGv; 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 sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id b6-20020a170906d10600b0097381ff4686si3470058ejz.643.2023.05.29.01.35.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 May 2023 01:35:54 -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=v76ZnpGv; 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 6C41E3882AFE for ; Mon, 29 May 2023 08:32:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C41E3882AFE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685349172; bh=A6TLcVHgwKWDoDqVbLV0pMXh4IMZght+sL8gojeHLFY=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=v76ZnpGvkuROYji/vn1aN8e2TpdyYawfXlzAZu8rvZ6VM5E/TLB22s9FKRZt5sB0D sjXQbrfNoXLGH6b8PILrUvHd47MU1MvIW13L3twMlw4vrNnqqEN4LPZ1hP+ewynl2z mw1jNtVRsDzpsUWfYpiQ0ShWVoWH9GwX5HcFM1wI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 4A9443856948 for ; Mon, 29 May 2023 08:29:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4A9443856948 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-30aea656e36so432385f8f.1 for ; Mon, 29 May 2023 01:29:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685348946; x=1687940946; 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=A6TLcVHgwKWDoDqVbLV0pMXh4IMZght+sL8gojeHLFY=; b=gdD/bfJRYoF0LSgIMkBKWzVhJbUxOlG4fXFy0lbu2u5Z7Xf3ZZN0gdG7C2mHIPtW7b PgpVObm/5msGkGtNDncJKYGi6JWVA5WwEXbEhWt2kAMnIFJ9bJzq8464hyWczFmZljJD uI5wgzSeLJ7EHNdiqusTjPLo10N0sEhf9yfV4rlARuinNkUUTgjM5EHiiQSnCwBJPR59 OYghUnOwVnCyRKkLL7ga2OHkVbUe2vj49fXS+6hGDcFMrhTRtv2qY3AYf6tits+2iI7h 3IOb4KdH4+WAyaPs458iIfPWOIS09slXB7lKbK/WORpbQi+F3yA8iqEEEVcebS0tdza9 4fwA== X-Gm-Message-State: AC+VfDzAaYQeAF1rPZ0GxgHdMXCnKj8oor/yXY5m0HLYJPE3PNKW7GXR KZQ2gh8R/bMWsUasaBanM6gsQVPj7T+yxKy7tAczJQ== X-Received: by 2002:a5d:668d:0:b0:30a:ee20:249a with SMTP id l13-20020a5d668d000000b0030aee20249amr1003267wru.6.1685348946187; Mon, 29 May 2023 01:29:06 -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 e10-20020a5d530a000000b002f6176cc6desm13077201wrv.110.2023.05.29.01.29.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 May 2023 01:29:05 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Fix spurious error on nested instantiations with generic renaming Date: Mon, 29 May 2023 10:29:04 +0200 Message-Id: <20230529082904.2409517-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?1767216885185556346?= X-GMAIL-MSGID: =?utf-8?q?1767216885185556346?= From: Eric Botcazou The problem is that the renaming slightly changes the form of a global reference that was saved during the analysis of a generic package, and that is sufficient to fool the code adjusting global references during the instantiation. gcc/ada/ * sem_ch12.adb (Copy_Generic_Node): Test the original node kind for the sake of consistency. For identifiers and other entity names and operators, accept an expanded name as associated node. Replace "or" with "or else" in condtion and fix its formatting. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_ch12.adb | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb index a9a3e322917..2562d1a0812 100644 --- a/gcc/ada/sem_ch12.adb +++ b/gcc/ada/sem_ch12.adb @@ -7953,11 +7953,11 @@ package body Sem_Ch12 is -- Special casing for identifiers and other entity names and operators - if Nkind (New_N) in N_Character_Literal - | N_Expanded_Name - | N_Identifier - | N_Operator_Symbol - | N_Op + if Nkind (N) in N_Character_Literal + | N_Expanded_Name + | N_Identifier + | N_Operator_Symbol + | N_Op then if not Instantiating then @@ -8161,6 +8161,15 @@ package body Sem_Ch12 is then Set_Entity (New_N, Assoc); + -- Cope with the rewriting into expanded name that may have + -- occurred in between, e.g. in Check_Generic_Child_Unit for + -- generic renaming declarations. + + elsif Nkind (Assoc) = N_Expanded_Name then + Rewrite (N, New_Copy_Tree (Assoc)); + Set_Associated_Node (N, Assoc); + return Copy_Generic_Node (N, Parent_Id, Instantiating); + -- The name in the call may be a selected component if the -- call has not been analyzed yet, as may be the case for -- pre/post conditions in a generic unit. @@ -8171,10 +8180,10 @@ package body Sem_Ch12 is Set_Entity (New_N, Entity (Name (Assoc))); elsif Nkind (Assoc) in N_Entity - and then (Expander_Active or - (GNATprove_Mode - and then not In_Spec_Expression - and then not Inside_A_Generic)) + and then (Expander_Active + or else (GNATprove_Mode + and then not In_Spec_Expression + and then not Inside_A_Generic)) then -- Inlining case: we are copying a tree that contains -- global entities, which are preserved in the copy to be