public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/65217] New: __builtin_unreachable in if statement causes bad assembly generation
@ 2015-02-26  7:37 sumnon at cj3 dot org
  2015-02-26  7:39 ` [Bug c/65217] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: sumnon at cj3 dot org @ 2015-02-26  7:37 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 65217
           Summary: __builtin_unreachable in if statement causes bad
                    assembly generation
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sumnon at cj3 dot org

Test case:

int expected(int n) {
    return n;
}

int test(int n) {
    if ((n & -n) != n) {
        __builtin_unreachable();
    }
    return n;
}

gcc -O3 -S test.c generates this:

    .file    "test.c"
    .text
    .p2align 4,,15
    .globl    expected
    .type    expected, @function
expected:
.LFB0:
    .cfi_startproc
    movl    %edi, %eax
    ret
    .cfi_endproc
.LFE0:
    .size    expected, .-expected
    .p2align 4,,15
    .globl    test
    .type    test, @function
test:
.LFB1:
    .cfi_startproc
    movl    %edi, %eax
    negl    %eax
    andl    %edi, %eax
    ret
    .cfi_endproc
.LFE1:
    .size    test, .-test
    .ident    "GCC: (GNU) 4.8.3 20140911 (Red Hat 4.8.3-7)"
    .section    .note.GNU-stack,"",@progbits

These functions should generate the same assembly, since the if statement in
function test does nothing that affects the return value.

I have and tested this with gcc 4.8.3; a friend tested this with gcc 4.9.2 and
got the same assembly.


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

end of thread, other threads:[~2015-04-28 14:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-26  7:37 [Bug c/65217] New: __builtin_unreachable in if statement causes bad assembly generation sumnon at cj3 dot org
2015-02-26  7:39 ` [Bug c/65217] " pinskia at gcc dot gnu.org
2015-02-26 15:04 ` hjl at gcc dot gnu.org
2015-04-27 11:08 ` [Bug tree-optimization/65217] " rguenth at gcc dot gnu.org
2015-04-28  4:02 ` law at gcc dot gnu.org
2015-04-28 14:26 ` law at redhat dot com

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