diff mbox

Fix dead_debug_insert_before ICE (PR debug/49522)

Message ID 20110704172938.GT16443@tyan-ft48-01.lab.bos.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek July 4, 2011, 5:29 p.m. UTC
Hi!

In dead_debug_* we don't immediately rescan insns, because that kills all
the df links we need to use, only queue their rescanning.

There are two kinds of changes we do on the debug insns without immediate
rescanning:
1) reset the debug insn
2) replace a reg use with DEBUG_EXPR of the same mode or
   subreg of a larger DEBUG_EXPR with the same outer mode as the reg

In the attached testcase on arm a debug insn is reset, because a multi-reg
register has been used there and as the debug insn location was that
multi-reg register before, it is now VOIDmode after the reset - (clobber
(const_int 0)).  Fixed by disregarding the reset debug insns.  Changes
of kind 2) that needed rescanning don't need this, as the mode doesn't
change in that case.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/4.6?

2011-07-04  Jakub Jelinek  <jakub@redhat.com>

	PR debug/49522
	* df-problems.c (dead_debug_insert_before): Ignore uses
	where the use debug insn has been reset.

	* gcc.dg/debug/pr49522.c: New test.


	Jakub

Comments

Eric Botcazou July 5, 2011, 8:35 a.m. UTC | #1
> There are two kinds of changes we do on the debug insns without immediate
> rescanning:
> 1) reset the debug insn
> 2) replace a reg use with DEBUG_EXPR of the same mode or
>    subreg of a larger DEBUG_EXPR with the same outer mode as the reg
>
> In the attached testcase on arm a debug insn is reset, because a multi-reg
> register has been used there and as the debug insn location was that
> multi-reg register before, it is now VOIDmode after the reset - (clobber
> (const_int 0)).

That can happen only in this case, right?  Otherwise, for a single register, 
the debug insn would have been removed from debug->head already.  If so, how 
simpler would it be to remove the other uses in dead_debug_reset instead?
diff mbox

Patch

--- gcc/df-problems.c.jj	2011-06-17 11:02:19.000000000 +0200
+++ gcc/df-problems.c	2011-07-04 10:46:42.000000000 +0200
@@ -3148,6 +3148,7 @@  dead_debug_insert_before (struct dead_de
   struct dead_debug_use *cur;
   struct dead_debug_use *uses = NULL;
   struct dead_debug_use **usesp = &uses;
+  bool no_reg_ok = false;
   rtx reg = NULL;
   rtx dval;
   rtx bind;
@@ -3161,6 +3162,21 @@  dead_debug_insert_before (struct dead_de
     {
       if (DF_REF_REGNO (cur->use) == uregno)
 	{
+	  /* If cur->use insn has been meanwhile reset, but hasn't been
+	     rescanned, just ignore that use.  */
+	  if (DF_REF_REAL_LOC (cur->use)
+	      == &INSN_VAR_LOCATION_LOC (DF_REF_INSN (cur->use))
+	      && VAR_LOC_UNKNOWN_P (*DF_REF_REAL_LOC (cur->use)))
+	    {
+	      gcc_assert (debug->to_rescan != NULL
+			  && bitmap_bit_p (debug->to_rescan,
+					   INSN_UID (DF_REF_INSN (cur->use))));
+	      *tailp = cur->next;
+	      XDELETE (cur);
+	      if (!reg)
+		no_reg_ok = true;
+	      continue;
+	    }
 	  *usesp = cur;
 	  usesp = &cur->next;
 	  *tailp = cur->next;
@@ -3174,6 +3190,9 @@  dead_debug_insert_before (struct dead_de
 	tailp = &(*tailp)->next;
     }
 
+  if (no_reg_ok && !reg)
+    return;
+
   gcc_assert (reg);
 
   /* Create DEBUG_EXPR (and DEBUG_EXPR_DECL).  */
--- gcc/testsuite/gcc.dg/debug/pr49522.c.jj	2011-07-04 10:54:23.000000000 +0200
+++ gcc/testsuite/gcc.dg/debug/pr49522.c	2011-07-04 10:54:02.000000000 +0200
@@ -0,0 +1,41 @@ 
+/* PR debug/49522 */
+/* { dg-do compile } */
+/* { dg-options "-fcompare-debug" } */
+
+int val1 = 0L;
+volatile int val2 = 7L;
+long long val3;
+int *ptr = &val1;
+
+static int
+func1 ()
+{
+  return 0;
+}
+
+static short int
+func2 (short int a, unsigned int b)
+{
+  return !b ? a : a >> b;
+}
+
+static unsigned long long
+func3 (unsigned long long a, unsigned long long b)
+{
+  return !b ? a : a % b;
+}
+
+void
+func4 (unsigned short arg1, int arg2)
+{
+  for (arg2 = 0; arg2 < 2; arg2++)
+    {
+      *ptr = func3 (func3 (10, func2 (val3, val2)), val3);
+      for (arg1 = -14; arg1 > 14; arg1 = func1 ())
+	{
+	  *ptr = -1;
+	  if (foo ())
+	    ;
+	}
+    }
+}