From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7871) id 8FA803858024; Thu, 24 Nov 2022 10:12:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8FA803858024 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669284736; bh=x7S5UUncEbBmlDe75zc/a0f6Kd/IX4aFKh/U7ywFQ+Y=; h=From:To:Subject:Date:From; b=knMD/gIKyF5vR+0STePuGU3laU/C9BpQgRCLHnrczTpSq+BMGY12mRPyct0EWvBmJ 9oJzR4MWF9UgFT0+M/i66to9uedWhLMRpzrBs/VF/Ff7fAeKn6cuwDgThdUbKj/8e/ QSVdjyzkKlWIU+zLSI+OkWvkZHqHN7lzG91eFLaI= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Marc Poulhi?s To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4287] ada: Spurious error on Lock_Free protected type with discriminants X-Act-Checkin: gcc X-Git-Author: Justin Squirek X-Git-Refname: refs/heads/master X-Git-Oldrev: a42e39a7b974645d2820931357e99411fdb0beb6 X-Git-Newrev: af94026524eafbe1270e28e5142e5958a4dadf07 Message-Id: <20221124101216.8FA803858024@sourceware.org> Date: Thu, 24 Nov 2022 10:12:16 +0000 (GMT) List-Id: https://gcc.gnu.org/g:af94026524eafbe1270e28e5142e5958a4dadf07 commit r13-4287-gaf94026524eafbe1270e28e5142e5958a4dadf07 Author: Justin Squirek Date: Wed Nov 23 07:56:45 2022 +0000 ada: Spurious error on Lock_Free protected type with discriminants 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. Diff: --- 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.