From patchwork Thu Nov 24 10:12:45 2022 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: 61067 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8C8693852239 for ; Thu, 24 Nov 2022 10:13:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8C8693852239 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669284799; bh=dfamATLj0GfxIsSykDBk86sUTvN/3sKbgA++l4lRdIw=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Wrh0CPkqq5b16ak2Fctq0Ul8CGBvARLeNFfnVE22tVlIurE0V6KrfmGTRxNaQde4w nixigHCAsZCa7sUbgcyY/Quv49qUAIBZ8Yzq/paCdT8AdJtYo6kA/oPgv851nkaaU+ QrUXnum+itNIpBn3slrqZD7ZJc73AzboULpFIcig= 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 13C983852C4A for ; Thu, 24 Nov 2022 10:12:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 13C983852C4A Received: by mail-wr1-x42d.google.com with SMTP id x17so1755041wrn.6 for ; Thu, 24 Nov 2022 02:12:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=dfamATLj0GfxIsSykDBk86sUTvN/3sKbgA++l4lRdIw=; b=rUZaSdjJQpqIF1L/QFYWfkA0hI73vzxNIuAHzC+MBwC230KGFwpKeS6Bjunp4NlAEk Y22xBI68eBoyxCVd22SHEbDQL4XGrUMDZoSIhdj0an5Ll4Fz951boc0pUPKT65C4GBBZ VesLCQirtiry4IwTLXfVImF3VfWn46i7dOmYzbC5HARSIjCxpdjlStNb6c227S3dN9Zl 9NtVrZwh9lGb1fh+J8soVlUHySQ0UVydMoKPWtTZ+HhvTJErTCRGjnvUOFD9jy/PSAIK 4fQ2pJn6BittkVSSOIBKAZJH3MbCBsCbP5MaB86OcLRB5Ze282a5/lhcxq74zvIcK0uM GHkg== X-Gm-Message-State: ANoB5pkLqOwmMXxRKzYi7hWAxlvkHrwesf3is2+9vxrW/YVxPZvAelSE NzbaVHYyrjFLmuXErYCdGC+/oR0pW6BuWA== X-Google-Smtp-Source: AA0mqf6Pi2mYXD/pp75EBzp72WC6D3kplXuc5iqOrG5wTDmYpJwPiLXLQav5vUMk1SuSBcwLSVRPoA== X-Received: by 2002:adf:f0c6:0:b0:241:db78:c737 with SMTP id x6-20020adff0c6000000b00241db78c737mr10244221wro.132.1669284768826; Thu, 24 Nov 2022 02:12:48 -0800 (PST) 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 cc18-20020a5d5c12000000b002238ea5750csm1127166wrb.72.2022.11.24.02.12.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Nov 2022 02:12:48 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: Justin Squirek Subject: [COMMITTED] ada: Spurious error on Lock_Free protected type with discriminants Date: Thu, 24 Nov 2022 11:12:45 +0100 Message-Id: <20221124101245.445226-1-poulhies@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.4 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 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Justin Squirek This patch corrects an issue in the compiler whereby unprefixed discriminants appearing in protected subprograms were unable to be properly resolved - leading to spurious resolution errors. gcc/ada/ * sem_ch8.adb (Find_Direct_Name): Remove bypass to reanalyze incorrectly analyzed discriminals. (Set_Entity_Or_Discriminal): Avoid resetting the entity field of a discriminant reference to be the internally generated renaming when we are in strict preanalysis mode. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_ch8.adb | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb index ca306663791..841076bbd01 100644 --- a/gcc/ada/sem_ch8.adb +++ b/gcc/ada/sem_ch8.adb @@ -4891,6 +4891,18 @@ package body Sem_Ch8 is then null; + -- Don't replace the discriminant in strict preanalysis mode since + -- it can lead to errors during full analysis when the discriminant + -- gets referenced later. + + -- This can occur in situations where a protected type contains + -- an expression function which references a discriminant. + + elsif Preanalysis_Active + and then Inside_Preanalysis_Without_Freezing = 0 + then + null; + else Set_Entity (N, Discriminal (E)); end if; @@ -6048,21 +6060,6 @@ package body Sem_Ch8 is if Is_Type (Entity (N)) then Set_Etype (N, Entity (N)); - -- The exception to this general rule are constants associated with - -- discriminals of protected types because for each protected op - -- a new set of discriminals is internally created by the frontend - -- (see Exp_Ch9.Set_Discriminals), and the current decoration of the - -- entity pointer may have been set as part of a preanalysis, where - -- discriminals still reference the first subprogram or entry to be - -- expanded (see Expand_Protected_Body_Declarations). - - elsif Full_Analysis - and then Ekind (Entity (N)) = E_Constant - and then Present (Discriminal_Link (Entity (N))) - and then Is_Protected_Type (Scope (Discriminal_Link (Entity (N)))) - then - goto Find_Name; - else declare Entyp : constant Entity_Id := Etype (Entity (N)); @@ -6102,8 +6099,6 @@ package body Sem_Ch8 is return; end if; - <> - -- Preserve relevant elaboration-related attributes of the context which -- are no longer available or very expensive to recompute once analysis, -- resolution, and expansion are over.