From patchwork Fri Sep 10 13:26:17 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [Ada] Cross-Reference information for build-in-place objects X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 64391 Message-Id: <20100910132617.GA4004@adacore.com> To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Date: Fri, 10 Sep 2010 15:26:17 +0200 From: Arnaud Charlet List-Id: An object declaration of an indefinite type whose expression is a build-in- place function call is rewritten as a renaming declaration of a heap object. This patch sets the source location and Comes_From_Source flag of the entities involved in this rewriting, to ensure that references are properly collected for the defining entity of the original declaration. This produces a correct ALI file and removes spurious warnings. The following must compile quietly: gcc -c pack08.adb -gnat05 -gnatwu --- package Pack08 is type Node_Type is limited interface; type Node_Ref is access all Node_Type'Class; type Node_Cursor is limited interface; function Element (Position : Node_Cursor) return Node_Ref is abstract; function First_Child (Node : Node_Type) return Node_Cursor'Class is abstract; procedure P (Node : Node_Type'Class); end Pack08; -- package body Pack08 is procedure P (Node : Node_Type'Class) is Cursor : Node_Cursor'Class := Node.First_Child; Index : Node_Ref; begin Index := Cursor.Element; -- Line where the variable is used. end P; end Pack08; Tested on x86_64-pc-linux-gnu, committed on trunk 2010-09-10 Ed Schonberg * exp_ch6.adb (Make_Build_In_Place_In_Object_Declaration): Use proper sloc for renaming declaration and set Comes_From_Source properly to ensure that references are properly generated for an object declaration that is built in place. Index: exp_ch6.adb =================================================================== --- exp_ch6.adb (revision 164170) +++ exp_ch6.adb (working copy) @@ -5784,6 +5784,7 @@ Make_Explicit_Dereference (Loc, Prefix => New_Reference_To (Def_Id, Loc)); + Loc := Sloc (Object_Decl); Rewrite (Object_Decl, Make_Object_Renaming_Declaration (Loc, Defining_Identifier => Make_Temporary (Loc, 'D'), @@ -5821,6 +5822,14 @@ Set_Homonym (Renaming_Def_Id, Homonym (Obj_Def_Id)); Exchange_Entities (Renaming_Def_Id, Obj_Def_Id); + + -- Preserve source indication of original declaration, so that + -- xref information is properly generated for the right entity. + + Preserve_Comes_From_Source + (Object_Decl, Original_Node (Object_Decl)); + Set_Comes_From_Source (Obj_Def_Id, True); + Set_Comes_From_Source (Renaming_Def_Id, False); end; end if;