This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PR debug/46782] Skip debug insns in try_forward_edges


At -O0, we merge blocks or not depending on locus information present at
the last insn in a block and the entry locus of the subsequent block.
We shouldn't use the locus of a debug insn for this compare, lest we may
end up not merging blocks that, with -g0, we would.

This seldom occurs in practice, since this patch is only active at -O0,
and -fvar-tracking is disabled by default at -O0, even if -g is enabled.
However, since it's possible to explicitly activate -fvar-tracking (and
-fvar-tracking-assignments), even at -O0, we shouldn't generate
different executable code if the user does this.

The patch below was regstrapped on x86_64-linux-gnu.  Ok to install?

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

	PR debug/46782
	* cfgcleanup.c (try_forward_edges): Skip debug insns.
	
for  gcc/testsuite/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	PR debug/46782
	* gcc.dg/debug/pr46782.c: New.

Index: gcc/cfgcleanup.c
===================================================================
--- gcc/cfgcleanup.c.orig	2010-12-06 12:34:03.311495403 -0200
+++ gcc/cfgcleanup.c	2010-12-06 12:34:04.925493962 -0200
@@ -487,11 +487,17 @@ try_forward_edges (int mode, basic_block
 		    new_target = NULL;
 		  else
 		    {
+		      rtx last;
+
 		      if (new_locus)
 			locus = new_locus;
 
-		      new_locus = INSN_P (BB_END (target))
-				  ? INSN_LOCATOR (BB_END (target)) : 0;
+		      last = BB_END (target);
+		      if (DEBUG_INSN_P (last))
+			last = prev_nondebug_insn (last);
+
+		      new_locus = last && INSN_P (last)
+				  ? INSN_LOCATOR (last) : 0;
 
 		      if (new_locus && locus && !locator_eq (new_locus, locus))
 			new_target = NULL;
Index: gcc/testsuite/gcc.dg/debug/pr46782.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ gcc/testsuite/gcc.dg/debug/pr46782.c	2010-12-06 12:34:43.712495319 -0200
@@ -0,0 +1,11 @@
+/* PR debug/46782 */
+/* { dg-do compile } */
+/* { dg-options "-w -O0 -fvar-tracking -fcompare-debug" } */
+
+void foo (int i)
+{
+  if (i)
+    i++;
+  while (i)
+    ;
+}

-- 
Alexandre Oliva, freedom fighter    http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist      Red Hat Brazil Compiler Engineer

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]