public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/65922] New: Switch statement with __builtin_unreachable creates a wild branch
@ 2015-04-29  1:28 bergner at gcc dot gnu.org
  2015-04-29  1:33 ` [Bug middle-end/65922] " bergner at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: bergner at gcc dot gnu.org @ 2015-04-29  1:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65922

            Bug ID: 65922
           Summary: Switch statement with __builtin_unreachable creates a
                    wild branch
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bergner at gcc dot gnu.org
  Target Milestone: ---

The following test case compiled with -O2 creates a wild branch when it
generates the branch to the switch's "default" leg.  On both POWER and x86_64
(maybe others), it generates a branch with a label just past the last
instruction in the function.

POWER:

  .L.foo:
        cmplwi 7,4,6
        bgt 7,.L2
  [snip]
        blr
        .p2align 4,,15
  .L2:
        .long 0

X86_64:

  foo:
  .LFB0:
        .cfi_startproc
        cmpl    $6, %esi
        ja      .L2
  [snip]
        ret
        .p2align 4,,10
        .p2align 3
  .L2:
        .cfi_endproc
  .LFE0:
        .size   foo, .-foo

My guess is that since we've stated that the default leg is unreachable, we
should probably just delete the branch altogether, rather than allowing it to
branch into nowhere.  I'll note that I see the same behavior from GCC 4.8 thru
trunk.  The code from GCC 4.7 and earlier looks ok.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug middle-end/65922] Switch statement with __builtin_unreachable creates a wild branch
  2015-04-29  1:28 [Bug middle-end/65922] New: Switch statement with __builtin_unreachable creates a wild branch bergner at gcc dot gnu.org
@ 2015-04-29  1:33 ` bergner at gcc dot gnu.org
  2015-04-29  1:46 ` pinskia at gcc dot gnu.org
  2015-04-29  2:21 ` bergner at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: bergner at gcc dot gnu.org @ 2015-04-29  1:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65922

Peter Bergner <bergner at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |4.7.0
      Known to fail|                            |4.8.0, 4.9.0, 5.1.0, 6.0

--- Comment #1 from Peter Bergner <bergner at gcc dot gnu.org> ---
The last tree dump looks ok to me:

foo (unsigned char * ptr, unsigned int cond)
{
  unsigned char _5;
  unsigned char _6;
  unsigned char _8;
  unsigned char _9;

  <bb 2>:
  switch (cond_2(D)) <default: <L7>, case 0: <L9>, case 1 ... 4: <L1>, case 5:
<L6>, case 6: <L1>>

<L1>:
  _5 = *ptr_4(D);
  _6 = _5 + 1;
  *ptr_4(D) = _6;
  goto <bb 6> (<L9>);

<L6>:
  _8 = *ptr_4(D);
  _9 = _8 + 2;
  *ptr_4(D) = _9;
  goto <bb 6> (<L9>);

<L7>:
  __builtin_unreachable ();

<L9>:
  return;

}

But the first rtl code after expand looks suspect to me.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug middle-end/65922] Switch statement with __builtin_unreachable creates a wild branch
  2015-04-29  1:28 [Bug middle-end/65922] New: Switch statement with __builtin_unreachable creates a wild branch bergner at gcc dot gnu.org
  2015-04-29  1:33 ` [Bug middle-end/65922] " bergner at gcc dot gnu.org
@ 2015-04-29  1:46 ` pinskia at gcc dot gnu.org
  2015-04-29  2:21 ` bergner at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2015-04-29  1:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65922

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 51513.

*** This bug has been marked as a duplicate of bug 51513 ***


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug middle-end/65922] Switch statement with __builtin_unreachable creates a wild branch
  2015-04-29  1:28 [Bug middle-end/65922] New: Switch statement with __builtin_unreachable creates a wild branch bergner at gcc dot gnu.org
  2015-04-29  1:33 ` [Bug middle-end/65922] " bergner at gcc dot gnu.org
  2015-04-29  1:46 ` pinskia at gcc dot gnu.org
@ 2015-04-29  2:21 ` bergner at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: bergner at gcc dot gnu.org @ 2015-04-29  2:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65922

Peter Bergner <bergner at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |CLOSED

--- Comment #3 from Peter Bergner <bergner at gcc dot gnu.org> ---
Closing as a DUP.  I forgot to include the test case, so for posterity, here is
the test case reduced from PHP.

void
foo (unsigned char *ptr, unsigned int cond)
{
  switch (cond)
    {
    case 0:
      return;
    case 1:
    case 2:
    case 3:
    case 4:
    case 6:
      *ptr += 1;
      return;
    case 5:
      *ptr += 2;
      return;
    default:
      __builtin_unreachable ();
      break;
    }
}


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-04-29  2:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-29  1:28 [Bug middle-end/65922] New: Switch statement with __builtin_unreachable creates a wild branch bergner at gcc dot gnu.org
2015-04-29  1:33 ` [Bug middle-end/65922] " bergner at gcc dot gnu.org
2015-04-29  1:46 ` pinskia at gcc dot gnu.org
2015-04-29  2:21 ` bergner at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).