This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Optimization bug in current GCC CVS mainline

The following small program fails with current gcc 3.1 from CVS if the
i486 specific <bits/string.h> header is used with:
$ /opt/gcc-3.1-devel/bin/gcc -Wall strpbrk-test.c -O3 -g -march=pentiumpro -mcpu=i686;./a.out 
strpbrk flunked test 10

I'm appending some more information and the preprocessed sources.
Removing the first or last strcpy problem leads to a working program,
therefore it looks like gcc optimizes the second strcpy away :-(.

Any help is appreciated,

#define _GNU_SOURCE

#include <stdio.h>
#include <string.h>

char one[50];
const char *it = "<UNSET>";	/* Routine name for message routines. */
size_t errors = 0;

static void
check (int thing, int number)
  if (!thing)
      printf("%s flunked test %d\n", it, number);

static void
test_strpbrk (void)
  it = "strpbrk";
  (void) strcpy(one, "abcabdea");
  (void) strcpy(one, "");
  check(strpbrk(one, "bc") == NULL, 10);	/* Empty string. */
  (void) strcpy(one, "");

main (void)
  test_strpbrk ();
  return 0;

$ /opt/gcc-3.1-devel/bin/gcc -Wall strpbrk-test.c -O3 -g -march=pentiumpro -mcpu=i686 -save-temps -v
Reading specs from /opt/gcc-3.1-devel/lib/gcc-lib/i686-pc-linux-gnu/3.1/specs
Configured with: /cvs/gcc/configure --prefix=/opt/gcc-3.1-devel --enable-shared --enable-threads=posix --with-gnu-as --with-gnu-ld --disable-nls --with-system-zlib --enable-languages=c,objc,c++,f77,java
Thread model: posix
gcc version 3.1 20010505 (experimental)
 /opt/gcc-3.1-devel/lib/gcc-lib/i686-pc-linux-gnu/3.1/cpp0 -lang-c -v -D__GNUC__=3 -D__GNUC_MINOR__=1 -D__GNUC_PATCHLEVEL__=0 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__OPTIMIZE__ -D__STDC_HOSTED__=1 -Wall -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__i686 -D__i686__ -D__pentiumpro -D__pentiumpro__ -D__tune_i686__ -D__tune_pentiumpro__ strpbrk-test.c strpbrk-test.i
GNU CPP version 3.1 20010505 (experimental) (cpplib) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
End of search list.
 /opt/gcc-3.1-devel/lib/gcc-lib/i686-pc-linux-gnu/3.1/cc1 -fpreprocessed strpbrk-test.i -quiet -dumpbase strpbrk-test.c -march=pentiumpro -mcpu=i686 -g -O3 -Wall -version -o strpbrk-test.s
GNU CPP version 3.1 20010505 (experimental) (cpplib) (i386 Linux/ELF)
GNU C version 3.1 20010505 (experimental) (i686-pc-linux-gnu)
        compiled by GNU C version 3.1 20010505 (experimental).
 as -V -Qy -o strpbrk-test.o strpbrk-test.s
GNU assembler version 2.11.90 (i686-pc-linux-gnu) using BFD version 2.11.90
 /opt/gcc-3.1-devel/lib/gcc-lib/i686-pc-linux-gnu/3.1/collect2 -m elf_i386 -dynamic-linker /lib/ /usr/lib/crt1.o /usr/lib/crti.o /opt/gcc-3.1-devel/lib/gcc-lib/i686-pc-linux-gnu/3.1/crtbegin.o -L/opt/gcc-3.1-devel/lib/gcc-lib/i686-pc-linux-gnu/3.1 -L/opt/gcc-3.1-devel/lib/gcc-lib/i686-pc-linux-gnu/3.1/../../.. strpbrk-test.o -lgcc -lc -lgcc /opt/gcc-3.1-devel/lib/gcc-lib/i686-pc-linux-gnu/3.1/crtend.o /usr/lib/crtn.o


 Andreas Jaeger
  SuSE Labs

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]