The source file has the line
  if (gethostname(host,sizeof host) == -1) return -1;
Compiled without optimization:
$ ~/gcc34x/bin/gcc  -S -c -o - x.i | grep -A2 hostname
        call    gethostname
        cmpl    $-1, %eax
        jne     .L46
Compiled with -O2:
        call    gethostname
        movl    $-1, %eax
        cmpl    %eax, %eax
        je      .L83

Same results for gcc-3.4.3, gcc-3.4.4, gcc-3.4-20050524.  gcc-4.0.0
and gcc-4.1-20050522 create correct code.

Reading specs from
/home/rick/gcc34x/bin/../lib/gcc/x86_64-unknown-linux-gnu/3.4.5/specs
Configured with: ./configure --prefix=/home/rick/gcc34x/
Thread model: posix
gcc version 3.4.5 20050524 (prerelease)
 /home/rick/gcc34x/bin/../libexec/gcc/x86_64-unknown-linux-gnu/3.4.5/cc1
-fpreprocessed x.i -quiet -dumpbase x.i -mtune=k8 -auxbase-strip /dev/null
-version -o /dev/null
GNU C version 3.4.5 20050524 (prerelease) (x86_64-unknown-linux-gnu)
        compiled by GNU C version 3.4.3 20041212 (Red Hat 3.4.3-9.EL4).
GGC heuristics: --param ggc-min-expand=94 --param ggc-min-heapsize=120284

-- 
           Summary: gcc generates incorrect code on x86_64 with -O2
           Product: gcc
           Version: 3.4.5
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rick-gcc at frob dot com dot au
                CC: gcc-bugs at gcc dot gnu dot org
 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=21804

Reply via email to