From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7871) id C15BB3858020; Mon, 28 Nov 2022 12:04:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C15BB3858020 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669637043; bh=f4Gz3jigrTs7EIS1IzxfDZ2VhqEuqeFl+xn9TDeU/WI=; h=From:To:Subject:Date:From; b=cBvm9M6ypV0Ytawho6kt+yOJ3lgpjK0ltnk4KFEb3TKySfwP/tKZICKQj0oEH9L9S bNPTapZz9UC6s4XSfYFOOjk5GwXZB8KnbZb0g865mqUumw2t2za6hkNaLuZgmw2oa3 sa/LnrVTjE29kbArDbETdFvkepc9N+yYDiO9QArc= 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-4360] ada: Fix internal error on conversion as in/out actual with -gnatVa X-Act-Checkin: gcc X-Git-Author: Eric Botcazou X-Git-Refname: refs/heads/master X-Git-Oldrev: f2b30a724e6bf7ff8e591b176967d596cee7648e X-Git-Newrev: e75d06f9bfad341aea3565f95fffb8937de5f142 Message-Id: <20221128120403.C15BB3858020@sourceware.org> Date: Mon, 28 Nov 2022 12:04:03 +0000 (GMT) List-Id: https://gcc.gnu.org/g:e75d06f9bfad341aea3565f95fffb8937de5f142 commit r13-4360-ge75d06f9bfad341aea3565f95fffb8937de5f142 Author: Eric Botcazou Date: Fri Nov 25 10:28:18 2022 +0100 ada: Fix internal error on conversion as in/out actual with -gnatVa The problem is that the regular expansion of the conversion around the call to the subprogram is disabled by the expansion of the validity check around the same call, as documented in Expand_Actuals: -- This case is given higher priority because the subsequent check -- for type conversion may add an extra copy of the variable and -- prevent proper value propagation back in the original object. Now the two mechanisms need to cooperate in order for the code to compile. gcc/ada/ * exp_ch6.adb (Expand_Actuals.Add_Call_By_Copy_Code): Deal with a reference to a validation variable in the actual. (Expand_Actuals.Add_Validation_Call_By_Copy_Code): Minor tweak. (Expand_Actuals): Call Add_Validation_Call_By_Copy_Code directly only if Add_Call_By_Copy_Code is not to be invoked. Diff: --- gcc/ada/exp_ch6.adb | 61 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb index 237a19d1327..0fe980c499a 100644 --- a/gcc/ada/exp_ch6.adb +++ b/gcc/ada/exp_ch6.adb @@ -1639,6 +1639,27 @@ package body Exp_Ch6 is Crep := False; end if; + -- If the actual denotes a variable which captures the value of an + -- object for validation purposes, we propagate the link with this + -- object to the new variable made from the actual just above. + + if Ekind (Formal) /= E_In_Parameter + and then Is_Validation_Variable_Reference (Actual) + then + declare + Ref : constant Node_Id := Unqual_Conv (Actual); + + begin + if Is_Entity_Name (Ref) then + Set_Validated_Object (Var, Validated_Object (Entity (Ref))); + + else + pragma Assert (False); + null; + end if; + end; + end if; + -- Setup initialization for case of in out parameter, or an out -- parameter where the formal is an unconstrained array (in the -- latter case, we have to pass in an object with bounds). @@ -1906,6 +1927,13 @@ package body Exp_Ch6 is Name => Lhs, Expression => Expr)); end if; + + -- Add a copy-back to reflect any potential changes in value + -- back into the original object, if any. + + if Is_Validation_Variable_Reference (Lhs) then + Add_Validation_Call_By_Copy_Code (Lhs); + end if; end; end if; end Add_Call_By_Copy_Code; @@ -2052,10 +2080,11 @@ package body Exp_Ch6 is -------------------------------------- procedure Add_Validation_Call_By_Copy_Code (Act : Node_Id) is + Var : constant Node_Id := Unqual_Conv (Act); + Expr : Node_Id; Obj : Node_Id; Obj_Typ : Entity_Id; - Var : constant Node_Id := Unqual_Conv (Act); Var_Id : Entity_Id; begin @@ -2405,26 +2434,10 @@ package body Exp_Ch6 is end if; end if; - -- The actual denotes a variable which captures the value of an - -- object for validation purposes. Add a copy-back to reflect any - -- potential changes in value back into the original object. - - -- Var : ... := Object; - -- if not Var'Valid then -- validity check - -- Call (Var); -- modify var - -- Object := Var; -- update Object - - -- This case is given higher priority because the subsequent check - -- for type conversion may add an extra copy of the variable and - -- prevent proper value propagation back in the original object. - - if Is_Validation_Variable_Reference (Actual) then - Add_Validation_Call_By_Copy_Code (Actual); - -- If argument is a type conversion for a type that is passed by -- copy, then we must pass the parameter by copy. - elsif Nkind (Actual) = N_Type_Conversion + if Nkind (Actual) = N_Type_Conversion and then (Is_Elementary_Type (E_Formal) or else Is_Bit_Packed_Array (Etype (Formal)) @@ -2508,6 +2521,18 @@ package body Exp_Ch6 is and then not In_Subrange_Of (E_Actual, E_Formal))) then Add_Call_By_Copy_Code; + + -- The actual denotes a variable which captures the value of an + -- object for validation purposes. Add a copy-back to reflect any + -- potential changes in value back into the original object. + + -- Var : ... := Object; + -- if not Var'Valid then -- validity check + -- Call (Var); -- modify var + -- Object := Var; -- update Object + + elsif Is_Validation_Variable_Reference (Actual) then + Add_Validation_Call_By_Copy_Code (Actual); end if; -- RM 3.2.4 (23/3): A predicate is checked on in-out and out