From b474d6c3f1ea034da14d20a52f183e4a1a0e7b87 Mon Sep 17 00:00:00 2001 From: Ed Schonberg Date: Wed, 3 Aug 2011 07:37:15 +0000 Subject: [PATCH] exp_ch9.adb (Build_Renamed_Formal_Declaration): common procedure for protected entries and task entries... 2011-08-03 Ed Schonberg * exp_ch9.adb (Build_Renamed_Formal_Declaration): common procedure for protected entries and task entries, to build the proper renaming declaration for entry formals, used in debugging. * exp_ch2.adb (Expand_Entry_Parameter): handle task and entry parameters in the same way. From-SVN: r177232 --- gcc/ada/ChangeLog | 8 +++ gcc/ada/exp_ch2.adb | 8 +-- gcc/ada/exp_ch9.adb | 116 +++++++++++++++++++++++++++++++------------- 3 files changed, 95 insertions(+), 37 deletions(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index a911edaab6d..2612b177fc8 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,11 @@ +2011-08-03 Ed Schonberg + + * exp_ch9.adb (Build_Renamed_Formal_Declaration): common procedure for + protected entries and task entries, to build the proper renaming + declaration for entry formals, used in debugging. + * exp_ch2.adb (Expand_Entry_Parameter): handle task and entry + parameters in the same way. + 2011-08-02 Robert Dewar * a-direct.adb, sinfo.ads, exp_ch9.adb, scng.adb, sem_util.adb, diff --git a/gcc/ada/exp_ch2.adb b/gcc/ada/exp_ch2.adb index e0be4042f11..68483ffb393 100644 --- a/gcc/ada/exp_ch2.adb +++ b/gcc/ada/exp_ch2.adb @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 1992-2009, Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2011, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -520,9 +520,6 @@ package body Exp_Ch2 is then Note_Possible_Modification (N, Sure => True); end if; - - Rewrite (N, New_Occurrence_Of (Renamed_Object (Entity (N)), Loc)); - return; end if; -- What we need is a reference to the corresponding component of the @@ -532,6 +529,9 @@ package body Exp_Ch2 is -- to turn this into a pointer to the parameter record and then we -- select the required parameter field. + -- The same processing applies to protected entries, where the Accept_ + -- Address is also the address of the Parameters record. + P_Comp_Ref := Make_Selected_Component (Loc, Prefix => diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb index 15db8b9668b..0a0a28a1ee2 100644 --- a/gcc/ada/exp_ch9.adb +++ b/gcc/ada/exp_ch9.adb @@ -170,6 +170,19 @@ package body Exp_Ch9 is -- and Decl is the enclosing synchronized type declaration at whose -- freeze point the generated body is analyzed. + function Build_Renamed_Formal_Declaration + (New_F : Entity_Id; + Formal : Entity_Id; + Comp : Entity_Id; + Renamed_Formal : Node_Id) return Node_Id; + -- Create a renaming declaration for a formal, within a protected entry + -- body or an accept body. The renamed object is a component of the + -- parameter block that is a parameter in the entry call. + + -- In Ada2012, If the formal is an incomplete tagged type, the renaming + -- does not dereference the corresponding component to prevent an illegal + -- use of the incomplete type (AI05-0151). + procedure Build_Wrapper_Bodies (Loc : Source_Ptr; Typ : Entity_Id; @@ -637,10 +650,11 @@ package body Exp_Ch9 is -- The name of the formal that holds the address of the parameter block -- for the call. - Comp : Entity_Id; - Decl : Node_Id; - Formal : Entity_Id; - New_F : Entity_Id; + Comp : Entity_Id; + Decl : Node_Id; + Formal : Entity_Id; + New_F : Entity_Id; + Renamed_Formal : Node_Id; begin Formal := First_Formal (Ent); @@ -667,18 +681,16 @@ package body Exp_Ch9 is Set_Actual_Subtype (New_F, Actual_Subtype (Formal)); + Renamed_Formal := + Make_Selected_Component (Loc, + Prefix => + Unchecked_Convert_To (Entry_Parameters_Type (Ent), + Make_Identifier (Loc, Chars (Ptr))), + Selector_Name => New_Reference_To (Comp, Loc)); + Decl := - Make_Object_Renaming_Declaration (Loc, - Defining_Identifier => New_F, - Subtype_Mark => - New_Reference_To (Etype (Formal), Loc), - Name => - Make_Explicit_Dereference (Loc, - Make_Selected_Component (Loc, - Prefix => - Unchecked_Convert_To (Entry_Parameters_Type (Ent), - Make_Identifier (Loc, Chars (Ptr))), - Selector_Name => New_Reference_To (Comp, Loc)))); + Build_Renamed_Formal_Declaration + (New_F, Formal, Comp, Renamed_Formal); Append (Decl, Decls); Set_Renamed_Object (Formal, New_F); @@ -1576,6 +1588,46 @@ package body Exp_Ch9 is return Rec_Nam; end Build_Parameter_Block; + -------------------------------------- + -- Build_Renamed_Formal_Declaration -- + -------------------------------------- + + function Build_Renamed_Formal_Declaration + (New_F : Entity_Id; + Formal : Entity_Id; + Comp : Entity_Id; + Renamed_Formal : Node_Id) return Node_Id + is + Loc : constant Source_Ptr := Sloc (New_F); + Decl : Node_Id; + + begin + -- If the formal is a tagged incomplete type, it is already passed + -- by reference, so it is sufficient to rename the pointer component + -- that corresponds to the actual. Otherwise we need to dereference + -- the pointer component to obtain the actual. + + if Is_Incomplete_Type (Etype (Formal)) + and then Is_Tagged_Type (Etype (Formal)) + then + Decl := + Make_Object_Renaming_Declaration (Loc, + Defining_Identifier => New_F, + Subtype_Mark => New_Reference_To (Etype (Comp), Loc), + Name => Renamed_Formal); + + else + Decl := + Make_Object_Renaming_Declaration (Loc, + Defining_Identifier => New_F, + Subtype_Mark => New_Reference_To (Etype (Formal), Loc), + Name => + Make_Explicit_Dereference (Loc, Renamed_Formal)); + end if; + + return Decl; + end Build_Renamed_Formal_Declaration; + ----------------------- -- Build_PPC_Wrapper -- ----------------------- @@ -4965,10 +5017,11 @@ package body Exp_Ch9 is and then Present (Handled_Statement_Sequence (N)) then declare - Comp : Entity_Id; - Decl : Node_Id; - Formal : Entity_Id; - New_F : Entity_Id; + Comp : Entity_Id; + Decl : Node_Id; + Formal : Entity_Id; + New_F : Entity_Id; + Renamed_Formal : Node_Id; begin Push_Scope (Ent); @@ -4997,21 +5050,18 @@ package body Exp_Ch9 is Set_Actual_Subtype (New_F, Actual_Subtype (Formal)); + Renamed_Formal := + Make_Selected_Component (Loc, + Prefix => + Unchecked_Convert_To ( + Entry_Parameters_Type (Ent), + New_Reference_To (Ann, Loc)), + Selector_Name => + New_Reference_To (Comp, Loc)); + Decl := - Make_Object_Renaming_Declaration (Loc, - Defining_Identifier => - New_F, - Subtype_Mark => - New_Reference_To (Etype (Formal), Loc), - Name => - Make_Explicit_Dereference (Loc, - Make_Selected_Component (Loc, - Prefix => - Unchecked_Convert_To ( - Entry_Parameters_Type (Ent), - New_Reference_To (Ann, Loc)), - Selector_Name => - New_Reference_To (Comp, Loc)))); + Build_Renamed_Formal_Declaration + (New_F, Formal, Comp, Renamed_Formal); if No (Declarations (N)) then Set_Declarations (N, New_List); -- 2.30.2