[PATCH] Instantiate DECL_RTLs in DECL_VALUE_EXPRs of arguments and block vars (PR debug/25562)

Jakub Jelinek jakub@redhat.com
Wed Dec 28 11:59:00 GMT 2005


Hi!

 int main(void)
 {
   int i = 7;
   int t[i];
   int j;
   for(j=0;j<i;j++)
     t[j] = j*j;
 }

emits with -g
         .uleb128 0x3    # (DIE (0x87) DW_TAG_variable)
         .ascii "t\0"    # DW_AT_name
         .byte   0x1     # DW_AT_decl_file
         .byte   0x5     # DW_AT_decl_line
         .long   0xa6    # DW_AT_type
         .byte   0x1     # DW_AT_location
         .byte   0x6     # DW_OP_deref
which is wrong, because DW_OP_deref needs an argument, but wasn't provided
one.  There are two problems on the GCC side.  One is that we should IMHO
never emit DW_OP_deref{,_size} if we couldn't represent the address operand
in the debug info (this is fixed by the dwarf2out.c part of the following
patch).  With it alone we just don't generate any DW_AT_location.

The second problem is why the address operand couldn't be represented.
The VLA (t in this testcase) has DECL_VALUE_EXPR *(t.1) and t.1 is a compiler
generated temporary pointer.  When not optimizing, t.1 is stored on the
stack, with (mem/f/c/i:DI (plus:DI (reg/f:DI 54 virtual-stack-vars)
(const_int -16 [0xfffffffffffffff0])) [0 t.1+0 S8 A64])
as DECL_RTL.  In GCC 4.0.x, rtl sharing caused t.1's DECL_RTL to be
instantiated during instantiate_virtual_regs time, when instantiating
some insn that set t.1.  But virtual reg instantiation changed since then
and the rtl is apparently no longer shared between DECL_RTL and the insn
that sets it.  The function.c part of the following patch fixes that by
instatiating virtual regs in DECL_RTLs of decls used in DECL_VALUE_EXPR
of block vars and arguments in addition to DECL_RTLs of the block vars.

Ok for trunk/4.1 if testing succeeds?

2005-12-28  Jakub Jelinek  <jakub@redhat.com>

	PR debug/25562
	* function.c (instantiate_expr): New function.
	(instantiate_decls_1, instantiate_decls): If DECL_HAS_VALUE_EXPR_P,
	walk its DECL_VALUE_EXPR with instantiate_expr.

	* dwarf2out.c (loc_descriptor_from_tree_1): Don't add
	DW_OP_deref{,_size} if address isn't going to be added.

--- gcc/function.c.jj	2005-12-20 13:43:56.000000000 +0100
+++ gcc/function.c	2005-12-28 12:40:15.000000000 +0100
@@ -1590,6 +1590,22 @@ instantiate_decl (rtx x)
   for_each_rtx (&XEXP (x, 0), instantiate_virtual_regs_in_rtx, NULL);
 }
 
+/* Helper for instantiate_decls called via walk_tree: Process all decls
+   in the given DECL_VALUE_EXPR.  */
+
+static tree
+instantiate_expr (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
+{
+  tree t = *tp;
+  if (! EXPR_P (t))
+    {
+      *walk_subtrees = 0;
+      if (DECL_P (t) && DECL_RTL_SET_P (t))
+	instantiate_decl (DECL_RTL (t));
+    }
+  return NULL;
+}
+
 /* Subroutine of instantiate_decls: Process all decls in the given
    BLOCK node and all its subblocks.  */
 
@@ -1599,8 +1615,15 @@ instantiate_decls_1 (tree let)
   tree t;
 
   for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
-    if (DECL_RTL_SET_P (t))
-      instantiate_decl (DECL_RTL (t));
+    {
+      if (DECL_RTL_SET_P (t))
+	instantiate_decl (DECL_RTL (t));
+      if (DECL_HAS_VALUE_EXPR_P (t))
+	{
+	  tree v = DECL_VALUE_EXPR (t);
+	  walk_tree (&v, instantiate_expr, NULL, NULL);
+	}
+    }
 
   /* Process all subblocks.  */
   for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
@@ -1620,6 +1643,11 @@ instantiate_decls (tree fndecl)
     {
       instantiate_decl (DECL_RTL (decl));
       instantiate_decl (DECL_INCOMING_RTL (decl));
+      if (DECL_HAS_VALUE_EXPR_P (decl))
+	{
+	  tree v = DECL_VALUE_EXPR (decl);
+	  walk_tree (&v, instantiate_expr, NULL, NULL);
+	}
     }
 
   /* Now process all variables defined in the function or its subblocks.  */
--- gcc/dwarf2out.c.jj	2005-12-20 13:43:56.000000000 +0100
+++ gcc/dwarf2out.c	2005-12-28 11:44:45.000000000 +0100
@@ -9420,7 +9420,7 @@ loc_descriptor_from_tree_1 (tree loc, in
     return 0;
 
   /* If we've got an address and don't want one, dereference.  */
-  if (!want_address && have_address)
+  if (!want_address && have_address && ret)
     {
       HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
 

	Jakub



More information about the Gcc-patches mailing list