re PR tree-optimization/54824 (ICE in verify_loop_structure)
authorRichard Biener <rguenther@suse.de>
Fri, 26 Oct 2012 10:12:35 +0000 (10:12 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Fri, 26 Oct 2012 10:12:35 +0000 (10:12 +0000)
2012-10-26  Richard Biener  <rguenther@suse.de>

PR middle-end/54824
* tree-optimize.c (execute_fixup_cfg): Insert __builtin_unreachable
at the end of blocks with no successors.

* gcc.dg/torture/pr54824.c: New testcase.

From-SVN: r192841

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr54824.c [new file with mode: 0644]
gcc/tree-optimize.c

index 4d0f9e00dc6dcf98ce2df638a5c5ace5d4c8a46f..96e604565a7d25c0566681569cdeabd23f9ebd76 100644 (file)
@@ -1,3 +1,9 @@
+2012-10-26  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/54824
+       * tree-optimize.c (execute_fixup_cfg): Insert __builtin_unreachable
+       at the end of blocks with no successors.
+
 2012-10-26  Alexander Ivchenko  <alexander.ivchenko@intel.com>
            Uros Bizjak  <ubizjak@gmail.com>
 
index 918af7526fe64e9fb0513df113dc13ec14cb7817..c3badec964f86bacb73eb611c185cfa9c893c54e 100644 (file)
@@ -1,3 +1,8 @@
+2012-10-26  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/54824
+       * gcc.dg/torture/pr54824.c: New testcase.
+
 2012-10-26  Alexander Ivchenko  <alexander.ivchenko@intel.com>
 
        * gcc.target/i386/fxsave-1.c: New.
diff --git a/gcc/testsuite/gcc.dg/torture/pr54824.c b/gcc/testsuite/gcc.dg/torture/pr54824.c
new file mode 100644 (file)
index 0000000..82b822b
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-w" } */
+
+void __attribute__((noreturn)) bar(void)
+{
+}
+
+void foo(int i, char *p, char *q)
+{
+  while (*p++) {
+      if (i)
+       p++;
+      if (!*q++)
+       bar();
+  }
+}
index d13c04f783c33baabc84efd8737e939afb3f3a71..3e7ca89e94da42976bb352fe9802a21dc861ba37 100644 (file)
@@ -180,6 +180,25 @@ execute_fixup_cfg (void)
       FOR_EACH_EDGE (e, ei, bb->succs)
         e->count = (e->count * count_scale
                    + REG_BR_PROB_BASE / 2) / REG_BR_PROB_BASE;
+
+      /* If we have a basic block with no successors that does not
+        end with a control statement or a noreturn call end it with
+        a call to __builtin_unreachable.  This situation can occur
+        when inlining a noreturn call that does in fact return.  */
+      if (EDGE_COUNT (bb->succs) == 0)
+       {
+         gimple stmt = last_stmt (bb);
+         if (!stmt
+             || (!is_ctrl_stmt (stmt)
+                 && (!is_gimple_call (stmt)
+                     || (gimple_call_flags (stmt) & ECF_NORETURN) == 0)))
+           {
+             stmt = gimple_build_call
+                 (builtin_decl_implicit (BUILT_IN_UNREACHABLE), 0);
+             gimple_stmt_iterator gsi = gsi_last_bb (bb);
+             gsi_insert_after (&gsi, stmt, GSI_NEW_STMT);
+           }
+       }
     }
   if (count_scale != REG_BR_PROB_BASE)
     compute_function_frequency ();