From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1285) id 8D4223876893; Wed, 27 Sep 2023 08:27:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8D4223876893 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1695803260; bh=5vHb8fC8DbPchRrD2fyIfGzMEE8y7QkulxJp4ZRQrgM=; h=From:To:Subject:Date:From; b=Mjb6cHjajXIMcx1VCEC+PQf1HJ5T9x2GhXLDtSx8YKV6pzDOYJCzkKZeVaErh6xda ECfbUpBc0W7X+UtrffVWSaT+b7TVnfMR3UpPvIk2Tk3gs+mDuYnnAjZY1R1SXyzQbU kAbIhlVny3R7m/ycX7mIwNCRhzeSyTWwGMx0f4h0= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Eric Botcazou To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-7896] ada: Fix wrong resolution for hidden discriminant in predicate X-Act-Checkin: gcc X-Git-Author: Eric Botcazou X-Git-Refname: refs/heads/releases/gcc-13 X-Git-Oldrev: fc26416ad7c9bd175b277421dd0c0e260bbf9dd8 X-Git-Newrev: 864411ef7ce8f4e1a1f931fb8474d10412c0636d Message-Id: <20230927082740.8D4223876893@sourceware.org> Date: Wed, 27 Sep 2023 08:27:40 +0000 (GMT) List-Id: https://gcc.gnu.org/g:864411ef7ce8f4e1a1f931fb8474d10412c0636d commit r13-7896-g864411ef7ce8f4e1a1f931fb8474d10412c0636d Author: Eric Botcazou Date: Mon Jul 3 00:33:18 2023 +0200 ada: Fix wrong resolution for hidden discriminant in predicate The problem occurs for hidden discriminants of private discriminated types. gcc/ada/ * sem_ch13.adb (Replace_Type_References_Generic.Visible_Component): In the case of private discriminated types, return a discriminant only if it is listed in the discriminant part of the declaration. Diff: --- gcc/ada/sem_ch13.adb | 49 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index cead44c52a1..d66255cdd9e 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -15439,15 +15439,11 @@ package body Sem_Ch13 is function Visible_Component (Comp : Name_Id) return Entity_Id is E : Entity_Id; + begin - -- Types with nameable components are record, task, and protected - -- types, and discriminated private types. + -- Types with nameable components are record, task, protected types - if Ekind (T) in E_Record_Type - | E_Task_Type - | E_Protected_Type - or else (Is_Private_Type (T) and then Has_Discriminants (T)) - then + if Ekind (T) in E_Record_Type | E_Task_Type | E_Protected_Type then -- This is a sequential search, which seems acceptable -- efficiency-wise, given the typical size of component -- lists, protected operation lists, task item lists, and @@ -15461,6 +15457,45 @@ package body Sem_Ch13 is Next_Entity (E); end loop; + + -- Private discriminated types may have visible discriminants + + elsif Is_Private_Type (T) and then Has_Discriminants (T) then + declare + Decl : constant Node_Id := Declaration_Node (T); + Spec : constant List_Id := + Discriminant_Specifications (Original_Node (Decl)); + + Discr : Node_Id; + + begin + -- Loop over the discriminants listed in the discriminant part + -- of the private type declaration to find one with a matching + -- name; then, if it exists, return the discriminant entity of + -- the same name in the type, which is that of its full view. + + if Present (Spec) then + Discr := First (Spec); + + while Present (Discr) loop + if Chars (Defining_Identifier (Discr)) = Comp then + Discr := First_Discriminant (T); + + while Present (Discr) loop + if Chars (Discr) = Comp then + return Discr; + end if; + + Next_Discriminant (Discr); + end loop; + + pragma Assert (False); + end if; + + Next (Discr); + end loop; + end if; + end; end if; -- Nothing by that name