This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug regression/48249] New: gcc-4.6: __builtin___memmove_chk wrong results


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

           Summary: gcc-4.6: __builtin___memmove_chk wrong results
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: regression
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: holger.hopp@sap.com


__builtin___memmove_chk produces wrong results if src and dest are
overlapping (gcc-4.6 rev. 171299 and trunk):

this is already wrong (source mm.c):

typedef long unsigned int size_t;

extern __inline __attribute__ ((__always_inline__)) __attribute__
((__artificial__)) void *
__attribute__ ((__nothrow__)) memmove (void *__restrict __dest, __const void
*__restrict __src, size_t __len)
{
  return __builtin___memmove_chk (__dest, __src, __len, __builtin_object_size
(__dest, 0));
}

void memmove2 (void *dest, const void *src, size_t n)
{
  memmove (dest, src, n);
}


correct test program that triggers wrong results (source m.c):

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

void memmove2 (void *dest, const void *src, size_t n);

int main()
{
  char s[50];
  strcpy (s, "abcdefghijklmnop");
  memmove2 (s+2, s, 14);
  printf ("%s\n", s);
  return 0;
}


reproduce (linux, x86_64):

$ gcc-4.6 -O2 -c mm.c -o mm46.o
$ gcc-4.5 -O2 -c mm.c -o mm45.o

gcc-4.6 is wrong:
$ gcc-4.6 m.c mm46.o && ./a.out
abababefefijklmn

gcc-4.5 produces correct result:
$ gcc-4.6 m.c mm45.o && ./a.out
ababcdefghijklmn


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