This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix ICE with __builtin_unreachable() as only statement in a function.


H.J. Lu wrote:
On Tue, Jun 16, 2009 at 11:18 AM, David Daney<ddaney@caviumnetworks.com> wrote:
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.


Is this the same as


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40445

If yes, you should include PR in ChangeLog.


I think it is a different issue. It would appear to only affect g++ and the ICE is at a different point. I will however look at it.


David Daney



H.J.
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))







Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]