@@ -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). */
@@ -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 ())
+ ;
+ }
+ }
+}