Fix ICE due to "combine" creating unreachable EH blocks (PR target/88861)
authorDavid Malcolm <dmalcolm@redhat.com>
Wed, 16 Jan 2019 20:13:23 +0000 (20:13 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Wed, 16 Jan 2019 20:13:23 +0000 (20:13 +0000)
PR target/88861 reports an ICE in "ce2" due to an unreachable
basic block.

The block becomes unreachable in "combine" when delete_noop_moves
deletes an insn with a REG_EH_REGION, deleting the EH edge, the
only edge leading to the basic block.

Normally, rest_of_handle_combine would call cleanup_cfg, deleting
unreachable blocks, if combine_instructions returns true, and
combine_instructions does return true for some cases of edge-removal,
but it doesn't for this case, leading to the ICE.

This patch updates delete_noop_moves so that it returns true if
it deletes any edges, and passes that through to combine_instructions,
so that it too will return true if any edges were deleted, ensuring that
cleanup_cfg will be called by rest_of_handle_combine for this case,
deleting the now-unreachable block, and fixing the ICE.

gcc/ChangeLog:
PR target/88861
* combine.c (delete_noop_moves): Convert to "bool" return,
returning true if any edges are eliminated.
(combine_instructions): Also return true if delete_noop_moves
returns true.

gcc/testsuite/ChangeLog:
PR target/88861
* g++.dg/torture/pr88861.C: New test.

From-SVN: r267984

gcc/ChangeLog
gcc/combine.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/torture/pr88861.C [new file with mode: 0644]

index 9460ad2..ec90897 100644 (file)
@@ -1,3 +1,11 @@
+2019-01-16  David Malcolm  <dmalcolm@redhat.com>
+
+       PR target/88861
+       * combine.c (delete_noop_moves): Convert to "bool" return,
+       returning true if any edges are eliminated.
+       (combine_instructions): Also return true if delete_noop_moves
+       returns true.
+
 2019-01-16  Tamar Christina  <tamar.christina@arm.com>
 
        * config/aarch64/aarch64-builtins.c (aarch64_simd_expand_args): Use
index e226c7d..c108f65 100644 (file)
@@ -983,14 +983,17 @@ combine_validate_cost (rtx_insn *i0, rtx_insn *i1, rtx_insn *i2, rtx_insn *i3,
 }
 
 
-/* Delete any insns that copy a register to itself.  */
+/* Delete any insns that copy a register to itself.
+   Return true if the CFG was changed.  */
 
-static void
+static bool
 delete_noop_moves (void)
 {
   rtx_insn *insn, *next;
   basic_block bb;
 
+  bool edges_deleted = false;
+
   FOR_EACH_BB_FN (bb, cfun)
     {
       for (insn = BB_HEAD (bb); insn != NEXT_INSN (BB_END (bb)); insn = next)
@@ -1001,10 +1004,12 @@ delete_noop_moves (void)
              if (dump_file)
                fprintf (dump_file, "deleting noop move %d\n", INSN_UID (insn));
 
-             delete_insn_and_edges (insn);
+             edges_deleted |= delete_insn_and_edges (insn);
            }
        }
     }
+
+  return edges_deleted;
 }
 
 \f
@@ -1143,8 +1148,8 @@ insn_a_feeds_b (rtx_insn *a, rtx_insn *b)
 /* Main entry point for combiner.  F is the first insn of the function.
    NREGS is the first unused pseudo-reg number.
 
-   Return nonzero if the combiner has turned an indirect jump
-   instruction into a direct jump.  */
+   Return nonzero if the CFG was changed (e.g. if the combiner has
+   turned an indirect jump instruction into a direct jump).  */
 static int
 combine_instructions (rtx_insn *f, unsigned int nregs)
 {
@@ -1529,7 +1534,7 @@ retry:
   default_rtl_profile ();
   clear_bb_flags ();
   new_direct_jump_p |= purge_all_dead_edges ();
-  delete_noop_moves ();
+  new_direct_jump_p |= delete_noop_moves ();
 
   /* Clean up.  */
   obstack_free (&insn_link_obstack, NULL);
index 004af23..d662e2a 100644 (file)
@@ -1,3 +1,8 @@
+2019-01-16  David Malcolm  <dmalcolm@redhat.com>
+
+       PR target/88861
+       * g++.dg/torture/pr88861.C: New test.
+
 2019-01-16  Tamar Christina  <tamar.christina@arm.com>
 
        PR debug/88046
diff --git a/gcc/testsuite/g++.dg/torture/pr88861.C b/gcc/testsuite/g++.dg/torture/pr88861.C
new file mode 100644 (file)
index 0000000..d2b6a4b
--- /dev/null
@@ -0,0 +1,11 @@
+// { dg-options "-fnon-call-exceptions" }
+
+struct Ax {
+  int n, a[];
+};
+
+int i = 12345678;
+int main() {
+  static Ax s{456, i};
+  ((s.a[0]) ? (void)0 : (void)0);
+}