This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix ICE with __builtin_unreachable() as only statement in a function.
- From: David Daney <ddaney at caviumnetworks dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 16 Jun 2009 11:18:22 -0700
- Subject: [PATCH] Fix ICE with __builtin_unreachable() as only statement in a function.
This patch fixed an ICE I found doing additional __builtin_unreachable()
testing.
If __builtin_unreachable() is the only statement in a function, the
resulting barrier will be the first non-note insn when doing barrier
cleanup. This causes SIGSEGV in cleanup_barriers. The fix is to check
for NULL before dereferencing.
Tested on x86_64-pc-linux-gnu all default languages. No regressions found.
OK to commit?
gcc/
2009-06-16 David Daney <ddaney@caviumnetworks.com>
* jump.c (cleanup_barriers): Handle case of no insns before a
barrier.
gcc/testsuite/
2009-06-16 David Daney <ddaney@caviumnetworks.com>
* gcc.dg/builtin-unreachable-3.c: New test.
Index: gcc/testsuite/gcc.dg/builtin-unreachable-3.c
===================================================================
--- gcc/testsuite/gcc.dg/builtin-unreachable-3.c (revision 0)
+++ gcc/testsuite/gcc.dg/builtin-unreachable-3.c (revision 0)
@@ -0,0 +1,9 @@
+/* Check that a function containing only __builtin_unreachable()
+ doesn't ICE. */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+const char *
+f (void)
+{
+ __builtin_unreachable ();
+}
Index: gcc/jump.c
===================================================================
--- gcc/jump.c (revision 148409)
+++ gcc/jump.c (working copy)
@@ -113,6 +113,11 @@ cleanup_barriers (void)
if (BARRIER_P (insn))
{
prev = prev_nonnote_insn (insn);
+ /* A function that contains only __builtin_unreachable() may
+ start with a barrier. In this case PREV will be
+ NULL. */
+ if (!prev)
+ continue;
if (BARRIER_P (prev))
delete_insn (insn);
else if (prev != PREV_INSN (insn))