From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2100) id 2DC323861004; Sat, 22 Aug 2020 22:44:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2DC323861004 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1598136243; bh=m740/+5+n+1jZ8H55SV/QI2Wb+UTCwRSEdJ+V/EYm78=; h=From:To:Subject:Date:From; b=JFUZR7xkuHaGuRm4FLmfcWRqSWx/5iNZnB8W1REmcrgseAUAUEqGGkIhCiKnNVkRq 7UokwnD2NlFFzbHoDm7QnDDNovGjx0UXTDyGoTkUU+U3cU2Qsy/rWyMY0vMFN90oXl Nqr9Q7FOvHi2n0ewH8qks6FtTV/Kb2WeIdJ3VgoI= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Giuliano Belinassi To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/autopar_devel] [Ada] Nested subprograms in protected subprograms improperly handled in GNAT-LLVM X-Act-Checkin: gcc X-Git-Author: Gary Dismukes X-Git-Refname: refs/heads/devel/autopar_devel X-Git-Oldrev: 1842eb299a732731792e43d57f7ef7ed2f99a41d X-Git-Newrev: 504106daecabd981fb1968f42681fa26e70ae42b Message-Id: <20200822224403.2DC323861004@sourceware.org> Date: Sat, 22 Aug 2020 22:44:03 +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: Sat, 22 Aug 2020 22:44:03 -0000 https://gcc.gnu.org/g:504106daecabd981fb1968f42681fa26e70ae42b commit 504106daecabd981fb1968f42681fa26e70ae42b Author: Gary Dismukes Date: Fri Apr 17 16:56:58 2020 -0400 [Ada] Nested subprograms in protected subprograms improperly handled in GNAT-LLVM 2020-06-17 Gary Dismukes gcc/ada/ * exp_ch9.adb (Build_Protected_Subp_Specification): Add ??? comment about the flag Has_Nested_Subprogram not being set here. (Expand_N_Protected_Body): If the original body for a protected subprogram has the flag Has_Nested_Subprogram set, then set that flag on the new unprotected subprogram body that's created for it, and reset the Scope fields of its top level declarations, which have been effectively taken from the original protected subprogram body. Add ??? comment about unclear testing of Corresponding_Spec. Diff: --- gcc/ada/exp_ch9.adb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb index 651ca1f70af..0b06ce50a03 100644 --- a/gcc/ada/exp_ch9.adb +++ b/gcc/ada/exp_ch9.adb @@ -3933,6 +3933,13 @@ package body Exp_Ch9 is Set_Is_Eliminated (New_Id, Is_Eliminated (Def_Id)); + -- It seems we should set Has_Nested_Subprogram here, but instead we + -- currently set it in Expand_N_Protected_Body, because the entity + -- created here isn't the one that Corresponding_Spec of the body + -- will later be set to, and that's the entity where it's needed. ??? + + Set_Has_Nested_Subprogram (New_Id, Has_Nested_Subprogram (Def_Id)); + if Nkind (Specification (Decl)) = N_Procedure_Specification then New_Spec := Make_Procedure_Specification (Loc, @@ -8716,10 +8723,32 @@ package body Exp_Ch9 is Current_Node := New_Op_Body; Analyze (New_Op_Body); + -- When the original protected body has nested subprograms, + -- the new body also has them, so set the flag accordingly + -- and reset the scopes of the top-level nested subprograms + -- and other declaration entities so that they now refer to + -- the new body's entity. (It would preferable to do this + -- within Build_Protected_Sub_Specification, which is called + -- from Build_Unprotected_Subprogram_Body, but the needed + -- subprogram entity isn't available via Corresponding_Spec + -- until after the above Analyze call.) + + if Has_Nested_Subprogram (Corresponding_Spec (Op_Body)) then + Set_Has_Nested_Subprogram + (Corresponding_Spec (New_Op_Body)); + + Reset_Scopes_To + (New_Op_Body, Corresponding_Spec (New_Op_Body)); + end if; + -- Build the corresponding protected operation. This is -- needed only if this is a public or private operation of -- the type. + -- Why do we need to test for Corresponding_Spec being + -- present here when it's assumed to be set further above + -- in the Is_Eliminated test??? + if Present (Corresponding_Spec (Op_Body)) then Op_Decl := Unit_Declaration_Node (Corresponding_Spec (Op_Body));