aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Daney <ddaney@caviumnetworks.com>2009-07-25 20:25:18 +0000
committerDavid Daney <daney@gcc.gnu.org>2009-07-25 20:25:18 +0000
commit1e211590c3288acd5ea6ff4edb94a1efd5ec25f7 (patch)
tree697b3a3928c509ec1d15830956e5fd590de886f9
parentba21aba3e53b2f9e9e365eb8bfe6f40b88cd6dca (diff)
downloadgcc-1e211590c3288acd5ea6ff4edb94a1efd5ec25f7.zip
gcc-1e211590c3288acd5ea6ff4edb94a1efd5ec25f7.tar.gz
gcc-1e211590c3288acd5ea6ff4edb94a1efd5ec25f7.tar.bz2
re PR rtl-optimization/40445 (g++ void f() { __builtin_unreachable(); })
2009-07-25 David Daney <ddaney@caviumnetworks.com> PR rtl-optimization/40445 * emit-rtl.c (next_nonnote_insn_bb): New function. * rtl.h (next_nonnote_insn_bb): Declare new function. * cfgcleanup.c (try_optimize_cfg): Don't remove an empty block with no successors that is the successor of the ENTRY_BLOCK. Continue from the top after removing an empty fallthrough block. * cfgrtl.c (get_last_bb_insn): Call next_nonnote_insn_bb instead of next_nonnote_insn. 2009-07-25 David Daney <ddaney@caviumnetworks.com> PR rtl-optimization/40445 * g++.dg/other/builtin-unreachable-1.C: New testcase. From-SVN: r150090
-rw-r--r--gcc/ChangeLog11
-rw-r--r--gcc/cfgcleanup.c11
-rw-r--r--gcc/cfgrtl.c4
-rw-r--r--gcc/emit-rtl.c19
-rw-r--r--gcc/rtl.h1
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/other/builtin-unreachable-1.C11
7 files changed, 58 insertions, 4 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 54806d1..3c39fb4 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,16 @@
2009-07-25 David Daney <ddaney@caviumnetworks.com>
+ PR rtl-optimization/40445
+ * emit-rtl.c (next_nonnote_insn_bb): New function.
+ * rtl.h (next_nonnote_insn_bb): Declare new function.
+ * cfgcleanup.c (try_optimize_cfg): Don't remove an empty block
+ with no successors that is the successor of the ENTRY_BLOCK.
+ Continue from the top after removing an empty fallthrough block.
+ * cfgrtl.c (get_last_bb_insn): Call next_nonnote_insn_bb instead
+ of next_nonnote_insn.
+
+2009-07-25 David Daney <ddaney@caviumnetworks.com>
+
* cfgcleanup.c (old_insns_match_p): Handle the case of empty
blocks.
diff --git a/gcc/cfgcleanup.c b/gcc/cfgcleanup.c
index 01ddf99..c631907 100644
--- a/gcc/cfgcleanup.c
+++ b/gcc/cfgcleanup.c
@@ -1846,10 +1846,16 @@ try_optimize_cfg (int mode)
/* Delete trivially dead basic blocks. This is either
blocks with no predecessors, or empty blocks with no
- successors. Empty blocks may result from expanding
+ successors. However if the empty block with no
+ successors is the successor of the ENTRY_BLOCK, it is
+ kept. This ensures that the ENTRY_BLOCK will have a
+ successor which is a precondition for many RTL
+ passes. Empty blocks may result from expanding
__builtin_unreachable (). */
if (EDGE_COUNT (b->preds) == 0
- || (EDGE_COUNT (b->succs) == 0 && BB_HEAD (b) == BB_END (b)))
+ || (EDGE_COUNT (b->succs) == 0
+ && BB_HEAD (b) == BB_END (b)
+ && single_succ_edge (ENTRY_BLOCK_PTR)->dest != b))
{
c = b->prev_bb;
if (dump_file)
@@ -1921,6 +1927,7 @@ try_optimize_cfg (int mode)
delete_basic_block (b);
changed = true;
b = c;
+ continue;
}
if (single_succ_p (b)
diff --git a/gcc/cfgrtl.c b/gcc/cfgrtl.c
index 78df3ff..3c877c2 100644
--- a/gcc/cfgrtl.c
+++ b/gcc/cfgrtl.c
@@ -1712,11 +1712,11 @@ get_last_bb_insn (basic_block bb)
end = tmp;
/* Include any barriers that may follow the basic block. */
- tmp = next_nonnote_insn (end);
+ tmp = next_nonnote_insn_bb (end);
while (tmp && BARRIER_P (tmp))
{
end = tmp;
- tmp = next_nonnote_insn (end);
+ tmp = next_nonnote_insn_bb (end);
}
return end;
diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index 5b42f4a..21d8434 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -2998,6 +2998,25 @@ next_nonnote_insn (rtx insn)
return insn;
}
+/* Return the next insn after INSN that is not a NOTE, but stop the
+ search before we enter another basic block. This routine does not
+ look inside SEQUENCEs. */
+
+rtx
+next_nonnote_insn_bb (rtx insn)
+{
+ while (insn)
+ {
+ insn = NEXT_INSN (insn);
+ if (insn == 0 || !NOTE_P (insn))
+ break;
+ if (NOTE_INSN_BASIC_BLOCK_P (insn))
+ return NULL_RTX;
+ }
+
+ return insn;
+}
+
/* Return the previous insn before INSN that is not a NOTE. This routine does
not look inside SEQUENCEs. */
diff --git a/gcc/rtl.h b/gcc/rtl.h
index 637c227..d5ae561 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -1626,6 +1626,7 @@ extern rtx previous_insn (rtx);
extern rtx next_insn (rtx);
extern rtx prev_nonnote_insn (rtx);
extern rtx next_nonnote_insn (rtx);
+extern rtx next_nonnote_insn_bb (rtx);
extern rtx prev_real_insn (rtx);
extern rtx next_real_insn (rtx);
extern rtx prev_active_insn (rtx);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index c982c25..a0e39e3 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,10 @@
2009-07-25 David Daney <ddaney@caviumnetworks.com>
+ PR rtl-optimization/40445
+ * g++.dg/other/builtin-unreachable-1.C: New testcase.
+
+2009-07-25 David Daney <ddaney@caviumnetworks.com>
+
* gcc.dg/builtin-unreachable-4.c: New test.
2009-07-25 Tobias Burnus <burnus@net-b.de>
diff --git a/gcc/testsuite/g++.dg/other/builtin-unreachable-1.C b/gcc/testsuite/g++.dg/other/builtin-unreachable-1.C
new file mode 100644
index 0000000..f6a5577
--- /dev/null
+++ b/gcc/testsuite/g++.dg/other/builtin-unreachable-1.C
@@ -0,0 +1,11 @@
+// PR c++/40445
+// Check that a function containing only __builtin_unreachable()
+// doesn't ICE.
+
+// { dg-do compile }
+// { dg-options "-O0" }
+const char *
+f (void)
+{
+ __builtin_unreachable ();
+}