re PR debug/83645 (ICE: in get_insn_template, at final.c:2100 with -gstatement-frontiers)
authorJakub Jelinek <jakub@redhat.com>
Wed, 3 Jan 2018 20:58:48 +0000 (21:58 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 3 Jan 2018 20:58:48 +0000 (21:58 +0100)
PR debug/83645
* var-tracking.c (delete_vta_debug_insn): New inline function.
(delete_vta_debug_insns): Add USE_CFG argument, if true, walk just
insns from get_insns () to NULL instead of each bb separately.
Use delete_vta_debug_insn.  No longer static.
(vt_debug_insns_local, variable_tracking_main_1): Adjust
delete_vta_debug_insns callers.
* rtl.h (delete_vta_debug_insns): Declare.
* final.c (rest_of_handle_final): Call delete_vta_debug_insns
instead of variable_tracking_main.

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

From-SVN: r256189

gcc/ChangeLog
gcc/final.c
gcc/rtl.h
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr83645.c [new file with mode: 0644]
gcc/var-tracking.c

index 8786a91..62856ce 100644 (file)
@@ -1,3 +1,16 @@
+2018-01-03  Jakub Jelinek  <jakub@redhat.com>
+
+       PR debug/83645
+       * var-tracking.c (delete_vta_debug_insn): New inline function.
+       (delete_vta_debug_insns): Add USE_CFG argument, if true, walk just
+       insns from get_insns () to NULL instead of each bb separately.
+       Use delete_vta_debug_insn.  No longer static.
+       (vt_debug_insns_local, variable_tracking_main_1): Adjust
+       delete_vta_debug_insns callers.
+       * rtl.h (delete_vta_debug_insns): Declare.
+       * final.c (rest_of_handle_final): Call delete_vta_debug_insns
+       instead of variable_tracking_main.
+
 2018-01-03  Martin Sebor  <msebor@redhat.com>
 
        PR c/83559
index b80693c..db3095c 100644 (file)
@@ -4544,7 +4544,7 @@ rest_of_handle_final (void)
   /* Turn debug markers into notes if the var-tracking pass has not
      been invoked.  */
   if (!flag_var_tracking && MAY_HAVE_DEBUG_MARKER_INSNS)
-    variable_tracking_main ();
+    delete_vta_debug_insns (false);
 
   assemble_start_function (current_function_decl, fnname);
   final_start_function (get_insns (), asm_out_file, optimize);
index 96513f4..e2a9c06 100644 (file)
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -4254,6 +4254,7 @@ extern GTY(()) rtx stack_limit_rtx;
 
 /* In var-tracking.c */
 extern unsigned int variable_tracking_main (void);
+extern void delete_vta_debug_insns (bool);
 
 /* In stor-layout.c.  */
 extern void get_mode_bounds (scalar_int_mode, int,
index 23c5d1c..e4d16a5 100644 (file)
@@ -1,3 +1,8 @@
+2018-01-03  Jakub Jelinek  <jakub@redhat.com>
+
+       PR debug/83645
+       * gcc.dg/pr83645.c: New test.
+
 2018-01-03  Martin Sebor  <msebor@redhat.com>
 
        PR c/83559
diff --git a/gcc/testsuite/gcc.dg/pr83645.c b/gcc/testsuite/gcc.dg/pr83645.c
new file mode 100644 (file)
index 0000000..4ac2be2
--- /dev/null
@@ -0,0 +1,14 @@
+/* PR debug/83645 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -g -fno-var-tracking" } */
+
+int a, b, c[1];
+
+void
+foo (void)
+{
+  int i = 0;
+  b = a;
+  for (;;)
+    c[i++] = 7;
+}
index e768c2d..98d09c0 100644 (file)
@@ -10271,11 +10271,40 @@ vt_initialize (void)
 
 static int debug_label_num = 1;
 
+/* Remove from the insn stream a single debug insn used for
+   variable tracking at assignments.  */
+
+static inline void
+delete_vta_debug_insn (rtx_insn *insn)
+{
+  if (DEBUG_MARKER_INSN_P (insn))
+    {
+      reemit_marker_as_note (insn);
+      return;
+    }
+
+  tree decl = INSN_VAR_LOCATION_DECL (insn);
+  if (TREE_CODE (decl) == LABEL_DECL
+      && DECL_NAME (decl)
+      && !DECL_RTL_SET_P (decl))
+    {
+      PUT_CODE (insn, NOTE);
+      NOTE_KIND (insn) = NOTE_INSN_DELETED_DEBUG_LABEL;
+      NOTE_DELETED_LABEL_NAME (insn)
+       = IDENTIFIER_POINTER (DECL_NAME (decl));
+      SET_DECL_RTL (decl, insn);
+      CODE_LABEL_NUMBER (insn) = debug_label_num++;
+    }
+  else
+    delete_insn (insn);
+}
+
 /* Remove from the insn stream all debug insns used for variable
-   tracking at assignments.  */
+   tracking at assignments.  USE_CFG should be false if the cfg is no
+   longer usable.  */
 
-static void
-delete_vta_debug_insns (void)
+void
+delete_vta_debug_insns (bool use_cfg)
 {
   basic_block bb;
   rtx_insn *insn, *next;
@@ -10283,33 +10312,20 @@ delete_vta_debug_insns (void)
   if (!MAY_HAVE_DEBUG_INSNS)
     return;
 
-  FOR_EACH_BB_FN (bb, cfun)
-    {
-      FOR_BB_INSNS_SAFE (bb, insn, next)
+  if (use_cfg)
+    FOR_EACH_BB_FN (bb, cfun)
+      {
+       FOR_BB_INSNS_SAFE (bb, insn, next)
+         if (DEBUG_INSN_P (insn))
+           delete_vta_debug_insn (insn);
+      }
+  else
+    for (insn = get_insns (); insn; insn = next)
+      {
+       next = NEXT_INSN (insn);
        if (DEBUG_INSN_P (insn))
-         {
-           if (DEBUG_MARKER_INSN_P (insn))
-             {
-               reemit_marker_as_note (insn);
-               continue;
-             }
-
-           tree decl = INSN_VAR_LOCATION_DECL (insn);
-           if (TREE_CODE (decl) == LABEL_DECL
-               && DECL_NAME (decl)
-               && !DECL_RTL_SET_P (decl))
-             {
-               PUT_CODE (insn, NOTE);
-               NOTE_KIND (insn) = NOTE_INSN_DELETED_DEBUG_LABEL;
-               NOTE_DELETED_LABEL_NAME (insn)
-                 = IDENTIFIER_POINTER (DECL_NAME (decl));
-               SET_DECL_RTL (decl, insn);
-               CODE_LABEL_NUMBER (insn) = debug_label_num++;
-             }
-           else
-             delete_insn (insn);
-         }
-    }
+         delete_vta_debug_insn (insn);
+      }
 }
 
 /* Run a fast, BB-local only version of var tracking, to take care of
@@ -10322,7 +10338,7 @@ static void
 vt_debug_insns_local (bool skipped ATTRIBUTE_UNUSED)
 {
   /* ??? Just skip it all for now.  */
-  delete_vta_debug_insns ();
+  delete_vta_debug_insns (true);
 }
 
 /* Free the data structures needed for variable tracking.  */
@@ -10395,7 +10411,7 @@ variable_tracking_main_1 (void)
         any pseudos at this point.  */
       || targetm.no_register_allocation)
     {
-      delete_vta_debug_insns ();
+      delete_vta_debug_insns (true);
       return 0;
     }
 
@@ -10423,7 +10439,7 @@ variable_tracking_main_1 (void)
     {
       vt_finalize ();
 
-      delete_vta_debug_insns ();
+      delete_vta_debug_insns (true);
 
       /* This is later restored by our caller.  */
       flag_var_tracking_assignments = 0;