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.