Patchwork [Ada] Cross-Reference information for build-in-place objects

login
register
mail settings
Submitter Arnaud Charlet
Date Sept. 10, 2010, 1:26 p.m.
Message ID <20100910132617.GA4004@adacore.com>
Download mbox | patch
Permalink /patch/64391/
State New
Headers show

Comments

Arnaud Charlet - Sept. 10, 2010, 1:26 p.m.
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  <schonberg@adacore.com>

	* 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.
Florian Weimer - Oct. 31, 2010, 5:01 p.m.
* Arnaud Charlet:

> 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.

It seems this fixes PR ada/37618.  Okay to apply this patch to the 4.4
and 4.5 branches (after bootstrapping and testing)?

Patch

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;