Patchwork Copy/update DECL_DEBUG_EXPR during inlining (PR tree-optimization/45083)

login
register
mail settings
Submitter Jakub Jelinek
Date July 27, 2010, 7:01 a.m.
Message ID <20100727070122.GS18378@tyan-ft48-01.lab.bos.redhat.com>
Download mbox | patch
Permalink /patch/59980/
State New
Headers show

Comments

Jakub Jelinek - July 27, 2010, 7:01 a.m.
Hi!

We don't currently copy/update DECL_DEBUG_EXPR during inlining, the
DECL_DEBUG_EXPR_IS_FROM bit is copied over to the new decls, but nothing
sets DECL_DEBUG_EXPR.  So, when early SRA creates some artificial vars
after inlining that 1) we print the artificial variable names in diagnostics
instead of the source expressions 2) accurate debug info for those SRA
optimized variables that were inlined can't be produced.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux.
Ok for trunk?

2010-07-27  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/45083
	* tree-inline.c (add_local_variables): Also remap DECL_DEBUG_EXPR.

	* gcc.dg/pr45083.c: New test.


	Jakub
Richard Guenther - July 27, 2010, 9:37 a.m.
On Tue, Jul 27, 2010 at 9:01 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> We don't currently copy/update DECL_DEBUG_EXPR during inlining, the
> DECL_DEBUG_EXPR_IS_FROM bit is copied over to the new decls, but nothing
> sets DECL_DEBUG_EXPR.  So, when early SRA creates some artificial vars
> after inlining that 1) we print the artificial variable names in diagnostics
> instead of the source expressions 2) accurate debug info for those SRA
> optimized variables that were inlined can't be produced.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux.
> Ok for trunk?

Ok.

Thanks,
Richard.

> 2010-07-27  Jakub Jelinek  <jakub@redhat.com>
>
>        PR tree-optimization/45083
>        * tree-inline.c (add_local_variables): Also remap DECL_DEBUG_EXPR.
>
>        * gcc.dg/pr45083.c: New test.
>
> --- gcc/tree-inline.c.jj        2010-07-22 11:35:37.000000000 +0200
> +++ gcc/tree-inline.c   2010-07-26 21:08:11.000000000 +0200
> @@ -3687,7 +3687,24 @@ add_local_variables (struct function *ca
>          add_local_decl (caller, var);
>       }
>     else if (!can_be_nonlocal (var, id))
> -      add_local_decl (caller, remap_decl (var, id));
> +      {
> +        tree new_var = remap_decl (var, id);
> +
> +        /* Remap debug-expressions.  */
> +       if (TREE_CODE (new_var) == VAR_DECL
> +           && DECL_DEBUG_EXPR_IS_FROM (new_var)
> +           && new_var != var)
> +         {
> +           tree tem = DECL_DEBUG_EXPR (var);
> +           bool old_regimplify = id->regimplify;
> +           id->remapping_type_depth++;
> +           walk_tree (&tem, copy_tree_body_r, id, NULL);
> +           id->remapping_type_depth--;
> +           id->regimplify = old_regimplify;
> +           SET_DECL_DEBUG_EXPR (new_var, tem);
> +         }
> +       add_local_decl (caller, new_var);
> +      }
>  }
>
>  /* Fetch callee declaration from the call graph edge going from NODE and
> --- gcc/testsuite/gcc.dg/pr45083.c.jj   2010-07-26 21:10:36.000000000 +0200
> +++ gcc/testsuite/gcc.dg/pr45083.c      2010-07-26 21:13:52.000000000 +0200
> @@ -0,0 +1,25 @@
> +/* PR tree-optimization/45083 */
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -Wuninitialized" } */
> +
> +struct S { char *a; unsigned b; unsigned c; };
> +extern int foo (const char *);
> +extern void bar (int, int);
> +
> +static void
> +baz (void)
> +{
> +  struct S cs[1];      /* { dg-message "was declared here" } */
> +  switch (cs->b)       /* { dg-warning "cs\[^\n\r\]*\\.b\[^\n\r\]*is used uninitialized" } */
> +    {
> +    case 101:
> +      if (foo (cs->a)) /* { dg-warning "cs\[^\n\r\]*\\.a\[^\n\r\]*may be used uninitialized" } */
> +       bar (cs->c, cs->b);     /* { dg-warning "cs\[^\n\r\]*\\.c\[^\n\r\]*may be used uninitialized" } */
> +    }
> +}
> +
> +void
> +test (void)
> +{
> +  baz ();
> +}
>
>        Jakub
>

Patch

--- gcc/tree-inline.c.jj	2010-07-22 11:35:37.000000000 +0200
+++ gcc/tree-inline.c	2010-07-26 21:08:11.000000000 +0200
@@ -3687,7 +3687,24 @@  add_local_variables (struct function *ca
 	  add_local_decl (caller, var);
       }
     else if (!can_be_nonlocal (var, id))
-      add_local_decl (caller, remap_decl (var, id));
+      {
+        tree new_var = remap_decl (var, id);
+
+        /* Remap debug-expressions.  */
+	if (TREE_CODE (new_var) == VAR_DECL
+	    && DECL_DEBUG_EXPR_IS_FROM (new_var)
+	    && new_var != var)
+	  {
+	    tree tem = DECL_DEBUG_EXPR (var);
+	    bool old_regimplify = id->regimplify;
+	    id->remapping_type_depth++;
+	    walk_tree (&tem, copy_tree_body_r, id, NULL);
+	    id->remapping_type_depth--;
+	    id->regimplify = old_regimplify;
+	    SET_DECL_DEBUG_EXPR (new_var, tem);
+	  }
+	add_local_decl (caller, new_var);
+      }
 }
 
 /* Fetch callee declaration from the call graph edge going from NODE and
--- gcc/testsuite/gcc.dg/pr45083.c.jj	2010-07-26 21:10:36.000000000 +0200
+++ gcc/testsuite/gcc.dg/pr45083.c	2010-07-26 21:13:52.000000000 +0200
@@ -0,0 +1,25 @@ 
+/* PR tree-optimization/45083 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wuninitialized" } */
+
+struct S { char *a; unsigned b; unsigned c; };
+extern int foo (const char *);
+extern void bar (int, int);
+
+static void
+baz (void)
+{
+  struct S cs[1];	/* { dg-message "was declared here" } */
+  switch (cs->b)	/* { dg-warning "cs\[^\n\r\]*\\.b\[^\n\r\]*is used uninitialized" } */
+    {
+    case 101:
+      if (foo (cs->a))	/* { dg-warning "cs\[^\n\r\]*\\.a\[^\n\r\]*may be used uninitialized" } */
+	bar (cs->c, cs->b);	/* { dg-warning "cs\[^\n\r\]*\\.c\[^\n\r\]*may be used uninitialized" } */
+    }
+}
+
+void
+test (void)
+{
+  baz ();
+}