From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1914) id 077C43850204; Mon, 4 Jul 2022 07:51:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 077C43850204 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Pierre-Marie de Rodat To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-1440] [Ada] Enforce deferred constant completion rules X-Act-Checkin: gcc X-Git-Author: Steve Baird X-Git-Refname: refs/heads/master X-Git-Oldrev: 4b766285b089ba1bce91a7644b9d97836e80cda3 X-Git-Newrev: f3451ba8aa3a54c6f09ee049a1a406603ed2ec30 Message-Id: <20220704075124.077C43850204@sourceware.org> Date: Mon, 4 Jul 2022 07:51:24 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Jul 2022 07:51:24 -0000 https://gcc.gnu.org/g:f3451ba8aa3a54c6f09ee049a1a406603ed2ec30 commit r13-1440-gf3451ba8aa3a54c6f09ee049a1a406603ed2ec30 Author: Steve Baird Date: Wed May 25 17:21:39 2022 -0700 [Ada] Enforce deferred constant completion rules If a constrained subtype is given when a deferred constant is declared, then the subtype given in the completion is required (at compile time) to be subject to a statically matching constraint. This rule was not properly enforced in some cases and constructs that should have been rejected were incorrectly accepted. gcc/ada/ * sem_ch3.adb (Check_Possible_Deferred_Completion): Delete Prev_Obj_Def formal parameter. Reorganize code so that statically matching check is also performed in the case where the subtype given in the initial declaration is constrained and the subtype given in the completion is not. Diff: --- gcc/ada/sem_ch3.adb | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb index 84971e3c0b1..93aa2ca2b0f 100644 --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -13126,7 +13126,6 @@ package body Sem_Ch3 is procedure Check_Possible_Deferred_Completion (Prev_Id : Entity_Id; - Prev_Obj_Def : Node_Id; Curr_Obj_Def : Node_Id); -- Determine whether the two object definitions describe the partial -- and the full view of a constrained deferred constant. Generate @@ -13146,15 +13145,16 @@ package body Sem_Ch3 is procedure Check_Possible_Deferred_Completion (Prev_Id : Entity_Id; - Prev_Obj_Def : Node_Id; Curr_Obj_Def : Node_Id) is + Curr_Typ : Entity_Id; + Prev_Typ : constant Entity_Id := Etype (Prev_Id); + Anon_Acc : constant Boolean := Is_Anonymous_Access_Type (Prev_Typ); + Mismatch : Boolean := False; begin - if Nkind (Prev_Obj_Def) = N_Subtype_Indication - and then Present (Constraint (Prev_Obj_Def)) - and then Nkind (Curr_Obj_Def) = N_Subtype_Indication - and then Present (Constraint (Curr_Obj_Def)) - then + if Anon_Acc then + null; + elsif Nkind (Curr_Obj_Def) = N_Subtype_Indication then declare Loc : constant Source_Ptr := Sloc (N); Def_Id : constant Entity_Id := Make_Temporary (Loc, 'S'); @@ -13167,13 +13167,32 @@ package body Sem_Ch3 is begin Insert_Before_And_Analyze (N, Decl); Set_Etype (Id, Def_Id); - - if not Subtypes_Statically_Match (Etype (Prev_Id), Def_Id) then - Error_Msg_Sloc := Sloc (Prev_Id); - Error_Msg_N ("subtype does not statically match deferred " - & "declaration #", N); - end if; + Curr_Typ := Def_Id; end; + else + Curr_Typ := Etype (Curr_Obj_Def); + end if; + + if Anon_Acc then + if Nkind (Curr_Obj_Def) /= N_Access_Definition then + Mismatch := True; + elsif Has_Null_Exclusion (Prev_Typ) + and then not Null_Exclusion_Present (Curr_Obj_Def) + then + Mismatch := True; + end if; + -- ??? Another check needed: mismatch if disagreement + -- between designated types/profiles . + else + Mismatch := + Is_Constrained (Prev_Typ) + and then not Subtypes_Statically_Match (Prev_Typ, Curr_Typ); + end if; + + if Mismatch then + Error_Msg_Sloc := Sloc (Prev_Id); + Error_Msg_N ("subtype does not statically match deferred " + & "declaration #", N); end if; end Check_Possible_Deferred_Completion; @@ -13316,7 +13335,6 @@ package body Sem_Ch3 is Check_Possible_Deferred_Completion (Prev_Id => Prev, - Prev_Obj_Def => Object_Definition (Parent (Prev)), Curr_Obj_Def => Obj_Def); Set_Full_View (Prev, Id);