[Ada] Fix debug info for renaming of dereferenced return value

Arnaud Charlet charlet@adacore.com
Mon Oct 14 12:47:00 GMT 2013


This fixes the debugging information generated for a variable renaming the
dereference of the return value of a function returning an access type.

The compiler was both materializing the renaming object and generating
the special debug renaming variable for it, without generating debugging
information for the temporary capturing the return value and linked to
by the debug renaming variable.

The compiler will now avoid to materialize the renaming object and generate
debugging information for the temporary in the following example:

   type P is access all Integer;
   X : aliased Integer := 42;

   function Val return P is
   begin
      return X'Access;
   end Val;

   V : Integer renames Val.all;

Tested on x86_64-pc-linux-gnu, committed on trunk

2013-10-14  Eric Botcazou  <ebotcazou@adacore.com>

	* exp_dbug.adb (Debug_Renaming_Declaration): Do not
	materialize the entity when the renamed object contains an
	N_Explicit_Dereference.
	* sem_ch8.adb (Analyze_Object_Renaming):
	If the renaming comes from source and the renamed object is a
	dereference, mark the prefix as needing debug information.

-------------- next part --------------
Index: exp_dbug.adb
===================================================================
--- exp_dbug.adb	(revision 203521)
+++ exp_dbug.adb	(working copy)
@@ -411,7 +411,6 @@
                Ren := Prefix (Ren);
 
             when N_Explicit_Dereference =>
-               Set_Materialize_Entity (Ent);
                Prepend_String_To_Buffer ("XA");
                Ren := Prefix (Ren);
 
Index: sem_ch8.adb
===================================================================
--- sem_ch8.adb	(revision 203523)
+++ sem_ch8.adb	(working copy)
@@ -1208,11 +1208,22 @@
       --  may have been rewritten in several ways.
 
       elsif Is_Object_Reference (Nam) then
-         if Comes_From_Source (N)
-           and then Is_Dependent_Component_Of_Mutable_Object (Nam)
-         then
-            Error_Msg_N
-              ("illegal renaming of discriminant-dependent component", Nam);
+         if Comes_From_Source (N) then
+            if Is_Dependent_Component_Of_Mutable_Object (Nam) then
+               Error_Msg_N
+                 ("illegal renaming of discriminant-dependent component", Nam);
+            end if;
+
+            --  If the renaming comes from source and the renamed object is a
+            --  dereference, then mark the prefix as needing debug information,
+            --  since it might have been rewritten hence internally generated
+            --  and Debug_Renaming_Declaration will link the renaming to it.
+
+            if Nkind (Nam) = N_Explicit_Dereference
+              and then Is_Entity_Name (Prefix (Nam))
+            then
+               Set_Debug_Info_Needed (Entity (Prefix (Nam)));
+            end if;
          end if;
 
       --  A static function call may have been folded into a literal


More information about the Gcc-patches mailing list