]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR debug/84875 (ICE in maybe_record_trace_start, at dwarf2cfi.c:2348...
authorJakub Jelinek <jakub@redhat.com>
Mon, 25 Jun 2018 17:36:14 +0000 (19:36 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 25 Jun 2018 17:36:14 +0000 (19:36 +0200)
Backported from mainline
2018-03-20  Jakub Jelinek  <jakub@redhat.com>

PR debug/84875
* dce.c (delete_unmarked_insns): Don't remove frame related noop moves
holding REG_CFA_RESTORE notes, instead turn them into a USE.

* gcc.dg/pr84875.c: New test.

From-SVN: r262081

gcc/ChangeLog
gcc/dce.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr84875.c [new file with mode: 0644]

index 321c20592f1e1620e744158c29d24d07d2355873..b3ffed6b477e964e7b9471602ae5943a94302b32 100644 (file)
@@ -3,6 +3,10 @@
        Backported from mainline
        2018-03-20  Jakub Jelinek  <jakub@redhat.com>
 
+       PR debug/84875
+       * dce.c (delete_unmarked_insns): Don't remove frame related noop moves
+       holding REG_CFA_RESTORE notes, instead turn them into a USE.
+
        PR c/84953
        * builtins.c (fold_builtin_strpbrk): For strpbrk(x, "") use type
        instead of TREE_TYPE (s1) for the return value.
index ea3fb00d433f60c4d58106ec917bc8d6a31f5aac..1526a78dc1b7429946b797655b747aaa1ea07f94 100644 (file)
--- a/gcc/dce.c
+++ b/gcc/dce.c
@@ -558,9 +558,19 @@ delete_unmarked_insns (void)
     FOR_BB_INSNS_REVERSE_SAFE (bb, insn, next)
       if (NONDEBUG_INSN_P (insn))
        {
+         rtx turn_into_use = NULL_RTX;
+
          /* Always delete no-op moves.  */
          if (noop_move_p (insn))
-           ;
+           {
+             if (RTX_FRAME_RELATED_P (insn))
+               turn_into_use
+                 = find_reg_note (insn, REG_CFA_RESTORE, NULL);
+             if (turn_into_use && REG_P (XEXP (turn_into_use, 0)))
+               turn_into_use = XEXP (turn_into_use, 0);
+             else
+               turn_into_use = NULL_RTX;
+           }
 
          /* Otherwise rely only on the DCE algorithm.  */
          else if (marked_insn_p (insn))
@@ -600,8 +610,19 @@ delete_unmarked_insns (void)
          if (CALL_P (insn))
            must_clean = true;
 
-         /* Now delete the insn.  */
-         delete_insn_and_edges (insn);
+         if (turn_into_use)
+           {
+             /* Don't remove frame related noop moves if they cary
+                REG_CFA_RESTORE note, while we don't need to emit any code,
+                we need it to emit the CFI restore note.  */
+             PATTERN (insn)
+               = gen_rtx_USE (GET_MODE (turn_into_use), turn_into_use);
+             INSN_CODE (insn) = -1;
+             df_insn_rescan (insn);
+           }
+         else
+           /* Now delete the insn.  */
+           delete_insn_and_edges (insn);
        }
 
   /* Deleted a pure or const call.  */
index 658c662ff16cbe41224f3190b58d4d19eb4d7fe8..f7f3f492e67fe8c532704f51526a73e4f42491fc 100644 (file)
@@ -3,6 +3,9 @@
        Backported from mainline
        2018-03-20  Jakub Jelinek  <jakub@redhat.com>
 
+       PR debug/84875
+       * gcc.dg/pr84875.c: New test.
+
        PR c/84953
        * gcc.dg/pr84953.c: New test.
 
diff --git a/gcc/testsuite/gcc.dg/pr84875.c b/gcc/testsuite/gcc.dg/pr84875.c
new file mode 100644 (file)
index 0000000..257176d
--- /dev/null
@@ -0,0 +1,28 @@
+/* PR debug/84875 */
+/* { dg-do compile } */
+/* { dg-options "-Os" } */
+/* { dg-additional-options "-fpie" { target pie } } */
+/* { dg-additional-options "-march=z196" { target s390*-*-* } } */
+
+static long *a[100];
+static int b[100];
+long *c;
+int d;
+void foo (long *);
+
+void
+bar ()
+{
+  long *g = c;
+  g--;
+  d = *g;
+  if (d)
+    if (b[d] < 8)
+      {
+       *(void **)g = a[d];
+       a[d] = g;
+       b[d]++;
+       return;
+      }
+  foo (g);
+}