GCC Version:
Using built-in specs.
COLLECT_GCC=/Apps/gcc45/bin/gcc
COLLECT_LTO_WRAPPER=/Apps/gcc45/libexec/gcc/x86_64-unknown-linux-gnu/4.5.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --prefix=/Apps/gcc45/ --enable-languages=c
Thread model: posix
gcc version 4.5.0 20091217 (experimental) (GCC) 

System:
Linux localhost 2.6.30-1-amd64 #1 SMP Sat Aug 15 18:09:19 UTC 2009 x86_64
GNU/Linux

Description:
 The following source:
extern int strlen3 (const char *) __attribute ((pure));
int z5 (const char *x)    {
  if (!(strlen3(x) < 10))
    __builtin_unreachable ();
  return 0;
}
 produces the following result with gcc -O2 t.c -S -Wall without any warnings
nor errors:
        .file   "t.c"
        .text
        .p2align 4,,15
.globl z5
        .type   z5, @function
z5:
.LFB0:
        .cfi_startproc
        subq    $8, %rsp
        .cfi_def_cfa_offset 16
        call    strlen3
        xorl    %eax, %eax
        addq    $8, %rsp
        .cfi_def_cfa_offset 8
        ret
        .cfi_endproc
.LFE0:
        .size   z5, .-z5
        .ident  "GCC: (GNU) 4.5.0 20091217 (experimental)"
        .section        .note.GNU-stack,"",@progbits

GCC should be able to remove the call to strlen3 from z5, since the only effect
of strlen3 is its return value which is no longer used by z5.


-- 
           Summary: Missed optimisation for pure functions with
                    __builtin_unreachable
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: patrick dot pelissier at gmail dot com
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


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

Reply via email to