diff mbox

[PR44248] Fix lto/whopr -g link-time -fcompare-debug failure

Message ID oriq5lkniz.fsf@livre.localdomain
State New
Headers show

Commit Message

Alexandre Oliva June 15, 2010, 3 a.m. UTC
When VTA is disabled, LTO streams in debug stmts as gimple nops.  This
is inadequate, for gimple nops will get in the way of removal of blocks
and perhaps other situations in which debug stmts are properly
disregarded.  Their presence is enough to bring about codegen
differences, causing -fcompare-debug failures when an object file
compiled with -g -flto is to be link-time compiled without -g, as is the
case when -fcompare-debug is given.

This patch arranges for us to drop the debug stmts entirely, but to do
so only after applying fixups.  We could drop them a bit earlier, while
filling in the stmts array, but then we'd have to worry about NULL stmt
entries in the array (should debug stmts have fixups) and the array
would probably be slower, for we'd have to test MAY_HAVE_DEBUG_STMTS
multiple times.

Is this ok, if it passes regstrap on x86_64-linux-gnu?

Comments

Richard Biener June 15, 2010, 8:31 a.m. UTC | #1
On Tue, Jun 15, 2010 at 5:00 AM, Alexandre Oliva <aoliva@redhat.com> wrote:
> When VTA is disabled, LTO streams in debug stmts as gimple nops.  This
> is inadequate, for gimple nops will get in the way of removal of blocks
> and perhaps other situations in which debug stmts are properly
> disregarded.  Their presence is enough to bring about codegen
> differences, causing -fcompare-debug failures when an object file
> compiled with -g -flto is to be link-time compiled without -g, as is the
> case when -fcompare-debug is given.
>
> This patch arranges for us to drop the debug stmts entirely, but to do
> so only after applying fixups.  We could drop them a bit earlier, while
> filling in the stmts array, but then we'd have to worry about NULL stmt
> entries in the array (should debug stmts have fixups) and the array
> would probably be slower, for we'd have to test MAY_HAVE_DEBUG_STMTS
> multiple times.
>
> Is this ok, if it passes regstrap on x86_64-linux-gnu?

Ok if you make input_bb return a flag whether a debug stmt was
streamed in, aggregate that and make the loop over all stmts
conditional on that to avoid walking over all stmts in a function
one more time.

Thanks,
Richard.
diff mbox

Patch

for  gcc/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	PR debug/44248
	* lto-streamer-in.c (input_bb): Leave debug stmts alone.
	(input_function): Drop them here, if VTA is disabled.
	
Index: gcc/lto-streamer-in.c
===================================================================
--- gcc/lto-streamer-in.c.orig	2010-06-14 23:22:09.000000000 -0300
+++ gcc/lto-streamer-in.c	2010-06-14 23:46:42.000000000 -0300
@@ -1204,13 +1204,6 @@  input_bb (struct lto_input_block *ib, en
     {
       gimple stmt = input_gimple_stmt (ib, data_in, fn, tag);
 
-      /* Change debug stmts to nops on-the-fly if we do not have VTA enabled.
-	 This allows us to build for example static libs with debugging
-	 enabled and do the final link without.  */
-      if (!MAY_HAVE_DEBUG_STMTS
-	  && is_gimple_debug (stmt))
-	stmt = gimple_build_nop ();
-
       find_referenced_vars_in (stmt);
       gsi_insert_after (&bsi, stmt, GSI_NEW_STMT);
 
@@ -1395,6 +1388,22 @@  input_function (tree fn_decl, struct dat
   free_dominance_info (CDI_DOMINATORS);
   free_dominance_info (CDI_POST_DOMINATORS);
   free (stmts);
+
+  /* Having applied fixups, drop debug stmts if VTA is disabled.  This
+     allows us to build for example static libs with debugging enabled
+     and do the final link without.  */
+  if (!MAY_HAVE_DEBUG_STMTS)
+    FOR_ALL_BB (bb)
+    {
+      gimple_stmt_iterator bsi = gsi_start_bb (bb);
+      while (!gsi_end_p (bsi))
+	{
+	  gimple_stmt_iterator gsi = bsi;
+	  gsi_next (&bsi);
+	  if (is_gimple_debug (gsi_stmt (gsi)))
+	    gsi_remove (&gsi, true);
+	}
+    }
 }