inline memcpy optimization bug?

Denys Duchier duchier@ps.uni-sb.de
Mon Nov 18 07:05:00 GMT 2002


I have a vague memory of seeing something about a bug when gcc
optimizes and inlines memcpy, but I can't locate it on the list.
Here is below a program which I compile with -march=pentium3 -O3 -pipe
-fomit-frame-pointer:

#include <iostream>
#include <string.h>
using namespace std;
int main()
{
  char* buffer = new char[8];
  const char head[] = {
    'A', 'B', 'C', 'D',
    'E', 'F', 'G', 'H'
  };
  asm("foo:");
  memcpy(buffer,head,sizeof(head));
  asm("baz:");
  for(int i=0;i<8;i++)
    cout << "[" << i << "] = " << head[i] << " , " << buffer[i] << endl;
  return 0;
}

when run it prints:

[0] = A , A
[1] = B , ┘
[2] = C , 
[3] = D ,
[4] = E , E
[5] = F , F
[6] = G , G
[7] = H , H

is this an old bug?  here is the info about my compiler:

Reading specs from /usr/lib/gcc-lib/i686-pc-linux-gnu/3.2/specs
Configured with: /var/tmp/portage/gcc-3.2-r2/work/gcc-3.2/configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --host=i686-pc-linux-gnu --build=i686-pc-linux-gnu --target=i686-pc-linux-gnu --with-system-zlib --enable-languages=c,c++,ada,f77,objc,java --enable-threads=posix --enable-long-long --disable-checking --enable-cstdio=stdio --enable-clocale=generic --enable-__cxa_atexit --enable-version-specific-runtime-libs --with-gxx-include-dir=/usr/include/g++-v32 --with-local-prefix=/usr/local --enable-shared --enable-nls --without-included-gettext
Thread model: posix
gcc version 3.2

--Denys



More information about the Gcc mailing list