On Tue, 13 Jan 2015, Jakub Jelinek wrote:

> On Tue, Jan 13, 2015 at 02:04:26PM +0100, Richard Biener wrote:
> > The following removes -fvar-tracking-assignments from being eligible
> > to the optimization attribute/pragma which fixes LTO operation for
> > mixed inputs (LTO just drops debug stmts if the flag is false).
> > 
> > In theory we could also fix inlining to do that when inlining
> > debug stmts into a non-VTA function but I think allowing this 
> > kind of per-function IL flags is just silly.
> 
> I actually think it makes sense to disable -fvar-tracking-assignments
> just for specific function, e.g. when it is known to be too expensive
> on some large function you don't care about debug info quality too much,
> while you still don't want to disable it on the whole TU level, because
> you have other functions (e.g. small ones) you still want to be able to
> debug often with good coverage.
> 
> So if this is fixable in the inliner and/or LTO in-streamer that would be
> my preference.

The following seems to work (for the testcase).  Testing coverage
of this mode will of course be bad.

Richard.

2015-01-13  Richard Biener  <rguent...@suse.de>

        PR lto/64415
        * tree-inline.c (insert_debug_decl_map): Check destination
        function MAY_HAVE_DEBUG_STMTS.
        (insert_init_debug_bind): Likewise.
        (insert_init_stmt): Remove redundant check.
        (remap_gimple_stmt): Drop debug stmts if the destination
        function has var-tracking assignments disabled.

        * gcc.dg/lto/pr64415_0.c: New testcase.
        * gcc.dg/lto/pr64415_1.c: Likewise. 

Index: gcc/testsuite/gcc.dg/lto/pr64415_0.c
===================================================================
--- gcc/testsuite/gcc.dg/lto/pr64415_0.c        (revision 0)
+++ gcc/testsuite/gcc.dg/lto/pr64415_0.c        (working copy)
@@ -0,0 +1,13 @@
+/* { dg-lto-do link } */
+/* { dg-require-effective-target fpic } */
+/* { dg-lto-options { { -O -flto -fpic } } } */
+/* { dg-extra-ld-options { -shared } } */
+
+extern void bar(char *, int);
+
+extern char *baz;
+
+void foo()
+{
+  bar(baz, 0);
+}
Index: gcc/testsuite/gcc.dg/lto/pr64415_1.c
===================================================================
--- gcc/testsuite/gcc.dg/lto/pr64415_1.c        (revision 0)
+++ gcc/testsuite/gcc.dg/lto/pr64415_1.c        (working copy)
@@ -0,0 +1,17 @@
+/* { dg-options "-g" } */
+
+extern int n;
+
+void bar(char *, int);
+
+inline void bar(char *s, int i)
+{
+  char *p = s;
+
+#ifdef V1
+  if (i)
+#else
+  if (n)
+#endif
+    *s = 0;
+}
Index: gcc/tree-inline.c
===================================================================
--- gcc/tree-inline.c   (revision 219520)
+++ gcc/tree-inline.c   (working copy)
@@ -192,7 +192,7 @@ insert_debug_decl_map (copy_body_data *i
   if (!gimple_in_ssa_p (id->src_cfun))
     return;
 
-  if (!MAY_HAVE_DEBUG_STMTS)
+  if (!opt_for_fn (id->dst_fn, flag_var_tracking_assignments))
     return;
 
   if (!target_for_debug_bind (key))
@@ -1348,6 +1348,10 @@ remap_gimple_stmt (gimple stmt, copy_bod
   bool skip_first = false;
   gimple_seq stmts = NULL;
 
+  if (is_gimple_debug (stmt)
+      && !opt_for_fn (id->dst_fn, flag_var_tracking_assignments))
+    return stmts;
+
   /* Begin by recognizing trees that we'll completely rewrite for the
      inlining context.  Our output for these trees is completely
      different from out input (e.g. RETURN_EXPR is deleted, and morphs
@@ -3007,7 +3011,7 @@ insert_init_debug_bind (copy_body_data *
   if (!gimple_in_ssa_p (id->src_cfun))
     return NULL;
 
-  if (!MAY_HAVE_DEBUG_STMTS)
+  if (!opt_for_fn (id->dst_fn, flag_var_tracking_assignments))
     return NULL;
 
   tracked_var = target_for_debug_bind (var);
@@ -3063,7 +3067,7 @@ insert_init_stmt (copy_body_data *id, ba
       gsi_insert_after (&si, init_stmt, GSI_NEW_STMT);
       gimple_regimplify_operands (init_stmt, &si);
 
-      if (!is_gimple_debug (init_stmt) && MAY_HAVE_DEBUG_STMTS)
+      if (!is_gimple_debug (init_stmt))
        {
          tree def = gimple_assign_lhs (init_stmt);
          insert_init_debug_bind (id, bb, def, def, init_stmt);

Reply via email to