From d7ff1e110e6765991e0ff3973a3556dddce98230 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 7 Jul 2011 18:05:55 +0200 Subject: [PATCH] re PR debug/49522 (Divide by zero in validate_subreg in emit-rtl.c:695) PR debug/49522 * df-problems.c (dead_debug_reset): Remove dead_debug_uses referencing debug insns that have been reset. (dead_debug_insert_before): Don't assert reg is non-NULL, instead return immediately if it is NULL. * gcc.dg/debug/pr49522.c: New test. M gcc/ChangeLog A gcc/testsuite/gcc.dg/debug/pr49522.c M gcc/testsuite/ChangeLog M gcc/df-problems.c From-SVN: r175987 --- gcc/ChangeLog | 8 ++++++ gcc/df-problems.c | 24 ++++++++++++++-- gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gcc.dg/debug/pr49522.c | 41 ++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/debug/pr49522.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c19bef8d316..88b0d81f3ae 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2011-07-07 Jakub Jelinek + + PR debug/49522 + * df-problems.c (dead_debug_reset): Remove dead_debug_uses + referencing debug insns that have been reset. + (dead_debug_insert_before): Don't assert reg is non-NULL, + instead return immediately if it is NULL. + 2011-07-07 Joseph Myers * config/i386/t-crtpic, config/i386/t-svr3dbx, config/pa/t-pa: diff --git a/gcc/df-problems.c b/gcc/df-problems.c index 59bed8bd667..e547b67c55f 100644 --- a/gcc/df-problems.c +++ b/gcc/df-problems.c @@ -3096,6 +3096,7 @@ static void dead_debug_reset (struct dead_debug *debug, unsigned int dregno) { struct dead_debug_use **tailp = &debug->head; + struct dead_debug_use **insnp = &debug->head; struct dead_debug_use *cur; rtx insn; @@ -3113,9 +3114,25 @@ dead_debug_reset (struct dead_debug *debug, unsigned int dregno) debug->to_rescan = BITMAP_ALLOC (NULL); bitmap_set_bit (debug->to_rescan, INSN_UID (insn)); XDELETE (cur); + /* If the current use isn't the first one attached to INSN, go back + to this first use. We assume that the uses attached to an insn + are adjacent. */ + if (tailp != insnp && DF_REF_INSN ((*insnp)->use) == insn) + tailp = insnp; + /* Then remove all the other uses attached to INSN. */ + while ((cur = *tailp) && DF_REF_INSN (cur->use) == insn) + { + *tailp = cur->next; + XDELETE (cur); + } + insnp = tailp; } else - tailp = &(*tailp)->next; + { + if (DF_REF_INSN ((*insnp)->use) != DF_REF_INSN (cur->use)) + insnp = tailp; + tailp = &(*tailp)->next; + } } } @@ -3174,7 +3191,10 @@ dead_debug_insert_before (struct dead_debug *debug, unsigned int uregno, tailp = &(*tailp)->next; } - gcc_assert (reg); + /* We may have dangling bits in debug->used for registers that were part + of a multi-register use, one component of which has been reset. */ + if (reg == NULL) + return; /* Create DEBUG_EXPR (and DEBUG_EXPR_DECL). */ dval = make_debug_expr_from_rtl (reg); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ea8d6f8cc40..c54bd86e958 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-07-07 Jakub Jelinek + + PR debug/49522 + * gcc.dg/debug/pr49522.c: New test. + 2011-07-07 Georg-Johann Lay * gcc.dg/pragma-align.c: Run only if target !default_packed. diff --git a/gcc/testsuite/gcc.dg/debug/pr49522.c b/gcc/testsuite/gcc.dg/debug/pr49522.c new file mode 100644 index 00000000000..3fa3bfb0e92 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/pr49522.c @@ -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 ()) + ; + } + } +} -- 2.30.2