[PATCH]: Fix PR/14638

Daniel Berlin dberlin@dberlin.org
Wed Dec 22 04:54:00 GMT 2004


This PR is a regression in our debug info generation, due to out-of-ssa 
splitting variables and us not being able to track that.

This is also a "cover PR" for the more general problem that we need to be 
able to track a *tree* that has been split into multiple variables in a 
sane way (we can already track the RTL).

The attached patch is a deceptively simple fix for this problem, made 
possible because we already have support for tracking this at the RTL 
level.
We just needed a way to say that "we've split this original user variable 
into these variables over here".

To do this was a four step process
1. i've simply taken what the docs say is unused field on 
var_decls (decl.vindex), and used it to store the user variable we were 
split from, for debug info purposes.

2. I told out-of-ssa to record what variable it's splitting from in that 
field.

3. Then, i've told the var-tracking code to track the value of the 
variable if the ultimate variable it is an alias of is not ignored for 
debug purposes.

4. I told dwarf2out's note_var_location to add the location of the split 
variable to the location list for the decl we are an alias of.

I think this is roughly the best we can do for now.

For the testcase in the PR:
foo (int b)
{
   int a = b;

loop:
   if (b > 0)
     {
       b--;
       goto loop;
     }

   return a + b;
}

main()
{
   printf ("%d\n", foo (93));
}

compiled with -O1 -fno-ivopts -g
(ivopt causes the whole function to just calculate a return value)

we will now properly associate the locations of the b.0 var that 
out-of-ssa creates with the user's b variable.
This can be seen simply by looking at the assembly/readelf output and 
noting that the locations noted as b.0 are also in b's location list.
Half the gdb's i have around don't seem to use the right values out of the 
location list anyway, but that's a gdb problem, since we clearly are 
saying b.0's values are that of b's, which is what we want.

We can also use this support for whenever we create new temporaries from 
existing ones, if we so choose (IE use it in more than just out-of-ssa).

This is currently bootstrapping and regtesting on my i686.
Okay for mainline if it passes?



-------------- next part --------------
2004-12-22  Daniel Berlin  <dberlin@dberlin.org>
	
	Fix PR debug/14638

	* tree.h (DECL_DEBUG_ALIAS_OF): New macro.
	* var-tracking.c (track_expr_p): Don't disqualify tracking of variables
	that are aliases of variables we want to track, unless the original 
	variable is also ignored for debugging purposes.
	* tree-outof-ssa.c (create_temp): Note who we are a debug alias of.
	* dwarf2out.c (dwarf2out_var_location): Add us to the location of the 
	decl we are an alias of.
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.669
diff -u -p -r1.669 tree.h
--- tree.h	21 Dec 2004 17:43:11 -0000	1.669
+++ tree.h	22 Dec 2004 04:37:35 -0000
@@ -2009,6 +2009,10 @@ struct tree_binfo GTY (())
    writing debugging information about vfield and vbase decls for C++.  */
 #define DECL_FCONTEXT(NODE) (FIELD_DECL_CHECK (NODE)->decl.vindex)
 
+/* For VAR_DECL, this is set to the variable we were split from, due to
+   optimization. */
+#define DECL_DEBUG_ALIAS_OF(NODE) (DECL_CHECK (NODE)->decl.vindex)
+
 /* Every ..._DECL node gets a unique number.  */
 #define DECL_UID(NODE) (DECL_CHECK (NODE)->decl.uid)
 
Index: var-tracking.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/var-tracking.c,v
retrieving revision 2.22
diff -u -p -r2.22 var-tracking.c
--- var-tracking.c	28 Sep 2004 07:59:52 -0000	2.22
+++ var-tracking.c	22 Dec 2004 04:37:37 -0000
@@ -1441,6 +1441,7 @@ static bool
 track_expr_p (tree expr)
 {
   rtx decl_rtl;
+  tree realdecl;
 
   /* If EXPR is not a parameter or a variable do not track it.  */
   if (TREE_CODE (expr) != VAR_DECL && TREE_CODE (expr) != PARM_DECL)
@@ -1454,14 +1455,18 @@ track_expr_p (tree expr)
   decl_rtl = DECL_RTL_IF_SET (expr);
   if (!decl_rtl)
     return 0;
+  
+  realdecl = expr;
+  while (DECL_DEBUG_ALIAS_OF (realdecl))
+    realdecl = DECL_DEBUG_ALIAS_OF  (realdecl);
 
   /* Do not track EXPR if it should be ignored for debugging purposes.  */
-  if (DECL_IGNORED_P (expr))
+  if (DECL_IGNORED_P (realdecl))
     return 0;
 
   /* Do not track global variables until we are able to emit correct location
      list for them.  */
-  if (TREE_STATIC (expr))
+  if (TREE_STATIC (realdecl))
     return 0;
 
   /* When the EXPR is a DECL for alias of some variable (see example)
Index: tree-outof-ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-outof-ssa.c,v
retrieving revision 2.36
diff -u -p -r2.36 tree-outof-ssa.c
--- tree-outof-ssa.c	14 Dec 2004 20:05:48 -0000	2.36
+++ tree-outof-ssa.c	22 Dec 2004 04:37:38 -0000
@@ -156,6 +156,7 @@ create_temp (tree t)
   if (name == NULL)
     name = "temp";
   tmp = create_tmp_var (type, name);
+  DECL_DEBUG_ALIAS_OF (tmp) = t;  
   DECL_ARTIFICIAL (tmp) = DECL_ARTIFICIAL (t);
   add_referenced_tmp_var (tmp);
 
Index: dwarf2out.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/dwarf2out.c,v
retrieving revision 1.562
diff -u -p -r1.562 dwarf2out.c
--- dwarf2out.c	9 Dec 2004 10:54:33 -0000	1.562
+++ dwarf2out.c	22 Dec 2004 04:37:41 -0000
@@ -13037,6 +13037,7 @@ dwarf2out_var_location (rtx loc_note)
   rtx prev_insn;
   static rtx last_insn;
   static const char *last_label;
+  tree decl;
 
   if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
     return;
@@ -13065,8 +13066,10 @@ dwarf2out_var_location (rtx loc_note)
 
   last_insn = loc_note;
   last_label = newloc->label;
-
-  add_var_loc_to_decl (NOTE_VAR_LOCATION_DECL (loc_note), newloc);
+  decl = NOTE_VAR_LOCATION_DECL (loc_note);
+  while (DECL_DEBUG_ALIAS_OF (decl) != NULL)
+    decl = DECL_DEBUG_ALIAS_OF (decl);
+  add_var_loc_to_decl (decl, newloc);
 }
 
 /* We need to reset the locations at the beginning of each


More information about the Gcc-patches mailing list