OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [gcc-4.5.1/] [gcc-4.5.1-or32-1.0rc1/] [gcc/] [testsuite/] [gcc.c-torture/] [execute/] [builtins/] [memcpy-chk.c] - Diff between revs 297 and 338

Only display areas with differences | Details | Blame | View Log

Rev 297 Rev 338
/* Copyright (C) 2004, 2005  Free Software Foundation.
/* Copyright (C) 2004, 2005  Free Software Foundation.
 
 
   Ensure builtin __memcpy_chk performs correctly.  */
   Ensure builtin __memcpy_chk performs correctly.  */
 
 
extern void abort (void);
extern void abort (void);
typedef __SIZE_TYPE__ size_t;
typedef __SIZE_TYPE__ size_t;
extern size_t strlen(const char *);
extern size_t strlen(const char *);
extern void *memcpy (void *, const void *, size_t);
extern void *memcpy (void *, const void *, size_t);
extern int memcmp (const void *, const void *, size_t);
extern int memcmp (const void *, const void *, size_t);
 
 
#include "chk.h"
#include "chk.h"
 
 
const char s1[] = "123";
const char s1[] = "123";
char p[32] = "";
char p[32] = "";
char *s2 = "defg";
char *s2 = "defg";
char *s3 = "FGH";
char *s3 = "FGH";
size_t l1 = 1;
size_t l1 = 1;
 
 
void
void
__attribute__((noinline))
__attribute__((noinline))
test1 (void)
test1 (void)
{
{
  int i;
  int i;
 
 
#if defined __i386__ || defined __x86_64__
#if defined __i386__ || defined __x86_64__
  /* The functions below might not be optimized into direct stores on all
  /* The functions below might not be optimized into direct stores on all
     arches.  It depends on how many instructions would be generated and
     arches.  It depends on how many instructions would be generated and
     what limits the architecture chooses in STORE_BY_PIECES_P.  */
     what limits the architecture chooses in STORE_BY_PIECES_P.  */
  memcpy_disallowed = 1;
  memcpy_disallowed = 1;
#endif
#endif
 
 
  /* All the memcpy calls in this routine except last have fixed length, so
  /* All the memcpy calls in this routine except last have fixed length, so
     object size checking should be done at compile time if optimizing.  */
     object size checking should be done at compile time if optimizing.  */
  chk_calls = 0;
  chk_calls = 0;
 
 
  if (memcpy (p, "ABCDE", 6) != p || memcmp (p, "ABCDE", 6))
  if (memcpy (p, "ABCDE", 6) != p || memcmp (p, "ABCDE", 6))
    abort ();
    abort ();
  if (memcpy (p + 16, "VWX" + 1, 2) != p + 16
  if (memcpy (p + 16, "VWX" + 1, 2) != p + 16
      || memcmp (p + 16, "WX\0\0", 5))
      || memcmp (p + 16, "WX\0\0", 5))
    abort ();
    abort ();
  if (memcpy (p + 1, "", 1) != p + 1 || memcmp (p, "A\0CDE", 6))
  if (memcpy (p + 1, "", 1) != p + 1 || memcmp (p, "A\0CDE", 6))
    abort ();
    abort ();
  if (memcpy (p + 3, "FGHI", 4) != p + 3 || memcmp (p, "A\0CFGHI", 8))
  if (memcpy (p + 3, "FGHI", 4) != p + 3 || memcmp (p, "A\0CFGHI", 8))
    abort ();
    abort ();
 
 
  i = 8;
  i = 8;
  memcpy (p + 20, "qrstu", 6);
  memcpy (p + 20, "qrstu", 6);
  memcpy (p + 25, "QRSTU", 6);
  memcpy (p + 25, "QRSTU", 6);
  if (memcpy (p + 25 + 1, s1, 3) != p + 25 + 1
  if (memcpy (p + 25 + 1, s1, 3) != p + 25 + 1
      || memcmp (p + 25, "Q123U", 6))
      || memcmp (p + 25, "Q123U", 6))
    abort ();
    abort ();
 
 
  if (memcpy (memcpy (p, "abcdEFG", 4) + 4, "efg", 4) != p + 4
  if (memcpy (memcpy (p, "abcdEFG", 4) + 4, "efg", 4) != p + 4
      || memcmp (p, "abcdefg", 8))
      || memcmp (p, "abcdefg", 8))
    abort();
    abort();
 
 
  /* Test at least one instance of the __builtin_ style.  We do this
  /* Test at least one instance of the __builtin_ style.  We do this
     to ensure that it works and that the prototype is correct.  */
     to ensure that it works and that the prototype is correct.  */
  if (__builtin_memcpy (p, "ABCDE", 6) != p || memcmp (p, "ABCDE", 6))
  if (__builtin_memcpy (p, "ABCDE", 6) != p || memcmp (p, "ABCDE", 6))
    abort ();
    abort ();
 
 
  memcpy (p + 5, s3, 1);
  memcpy (p + 5, s3, 1);
  if (memcmp (p, "ABCDEFg", 8))
  if (memcmp (p, "ABCDEFg", 8))
    abort ();
    abort ();
 
 
  memcpy_disallowed = 0;
  memcpy_disallowed = 0;
  if (chk_calls)
  if (chk_calls)
    abort ();
    abort ();
  chk_calls = 0;
  chk_calls = 0;
 
 
  memcpy (p + 6, s1 + 1, l1);
  memcpy (p + 6, s1 + 1, l1);
  if (memcmp (p, "ABCDEF2", 8))
  if (memcmp (p, "ABCDEF2", 8))
    abort ();
    abort ();
 
 
  /* The above memcpy copies into an object with known size, but
  /* The above memcpy copies into an object with known size, but
     unknown length, so it should be a __memcpy_chk call.  */
     unknown length, so it should be a __memcpy_chk call.  */
  if (chk_calls != 1)
  if (chk_calls != 1)
    abort ();
    abort ();
}
}
 
 
long buf1[64];
long buf1[64];
char *buf2 = (char *) (buf1 + 32);
char *buf2 = (char *) (buf1 + 32);
long buf5[20];
long buf5[20];
char buf7[20];
char buf7[20];
 
 
void
void
__attribute__((noinline))
__attribute__((noinline))
test2_sub (long *buf3, char *buf4, char *buf6, int n)
test2_sub (long *buf3, char *buf4, char *buf6, int n)
{
{
  int i = 0;
  int i = 0;
 
 
  /* All the memcpy/__builtin_memcpy/__builtin___memcpy_chk
  /* All the memcpy/__builtin_memcpy/__builtin___memcpy_chk
     calls in this routine are either fixed length, or have
     calls in this routine are either fixed length, or have
     side-effects in __builtin_object_size arguments, or
     side-effects in __builtin_object_size arguments, or
     dst doesn't point into a known object.  */
     dst doesn't point into a known object.  */
  chk_calls = 0;
  chk_calls = 0;
 
 
  /* These should probably be handled by store_by_pieces on most arches.  */
  /* These should probably be handled by store_by_pieces on most arches.  */
  if (memcpy (buf1, "ABCDEFGHI", 9) != (char *) buf1
  if (memcpy (buf1, "ABCDEFGHI", 9) != (char *) buf1
      || memcmp (buf1, "ABCDEFGHI\0", 11))
      || memcmp (buf1, "ABCDEFGHI\0", 11))
    abort ();
    abort ();
 
 
  if (memcpy (buf1, "abcdefghijklmnopq", 17) != (char *) buf1
  if (memcpy (buf1, "abcdefghijklmnopq", 17) != (char *) buf1
      || memcmp (buf1, "abcdefghijklmnopq\0", 19))
      || memcmp (buf1, "abcdefghijklmnopq\0", 19))
    abort ();
    abort ();
 
 
  if (__builtin_memcpy (buf3, "ABCDEF", 6) != (char *) buf1
  if (__builtin_memcpy (buf3, "ABCDEF", 6) != (char *) buf1
      || memcmp (buf1, "ABCDEFghijklmnopq\0", 19))
      || memcmp (buf1, "ABCDEFghijklmnopq\0", 19))
    abort ();
    abort ();
 
 
  if (__builtin_memcpy (buf3, "a", 1) != (char *) buf1
  if (__builtin_memcpy (buf3, "a", 1) != (char *) buf1
      || memcmp (buf1, "aBCDEFghijklmnopq\0", 19))
      || memcmp (buf1, "aBCDEFghijklmnopq\0", 19))
    abort ();
    abort ();
 
 
  if (memcpy ((char *) buf3 + 2, "bcd" + ++i, 2) != (char *) buf1 + 2
  if (memcpy ((char *) buf3 + 2, "bcd" + ++i, 2) != (char *) buf1 + 2
      || memcmp (buf1, "aBcdEFghijklmnopq\0", 19)
      || memcmp (buf1, "aBcdEFghijklmnopq\0", 19)
      || i != 1)
      || i != 1)
    abort ();
    abort ();
 
 
  /* These should probably be handled by move_by_pieces on most arches.  */
  /* These should probably be handled by move_by_pieces on most arches.  */
  if (memcpy ((char *) buf3 + 4, buf5, 6) != (char *) buf1 + 4
  if (memcpy ((char *) buf3 + 4, buf5, 6) != (char *) buf1 + 4
      || memcmp (buf1, "aBcdRSTUVWklmnopq\0", 19))
      || memcmp (buf1, "aBcdRSTUVWklmnopq\0", 19))
    abort ();
    abort ();
 
 
  if (__builtin_memcpy ((char *) buf1 + ++i + 8, (char *) buf5 + 1, 1)
  if (__builtin_memcpy ((char *) buf1 + ++i + 8, (char *) buf5 + 1, 1)
      != (char *) buf1 + 10
      != (char *) buf1 + 10
      || memcmp (buf1, "aBcdRSTUVWSlmnopq\0", 19)
      || memcmp (buf1, "aBcdRSTUVWSlmnopq\0", 19)
      || i != 2)
      || i != 2)
    abort ();
    abort ();
 
 
  if (memcpy ((char *) buf3 + 14, buf6, 2) != (char *) buf1 + 14
  if (memcpy ((char *) buf3 + 14, buf6, 2) != (char *) buf1 + 14
      || memcmp (buf1, "aBcdRSTUVWSlmnrsq\0", 19))
      || memcmp (buf1, "aBcdRSTUVWSlmnrsq\0", 19))
    abort ();
    abort ();
 
 
  if (memcpy (buf3, buf5, 8) != (char *) buf1
  if (memcpy (buf3, buf5, 8) != (char *) buf1
      || memcmp (buf1, "RSTUVWXYVWSlmnrsq\0", 19))
      || memcmp (buf1, "RSTUVWXYVWSlmnrsq\0", 19))
    abort ();
    abort ();
 
 
  if (memcpy (buf3, buf5, 17) != (char *) buf1
  if (memcpy (buf3, buf5, 17) != (char *) buf1
      || memcmp (buf1, "RSTUVWXYZ01234567\0", 19))
      || memcmp (buf1, "RSTUVWXYZ01234567\0", 19))
    abort ();
    abort ();
 
 
  __builtin_memcpy (buf3, "aBcdEFghijklmnopq\0", 19);
  __builtin_memcpy (buf3, "aBcdEFghijklmnopq\0", 19);
 
 
  /* These should be handled either by movmemendM or memcpy
  /* These should be handled either by movmemendM or memcpy
     call.  */
     call.  */
 
 
  /* buf3 points to an unknown object, so __memcpy_chk should not be done.  */
  /* buf3 points to an unknown object, so __memcpy_chk should not be done.  */
  if (memcpy ((char *) buf3 + 4, buf5, n + 6) != (char *) buf1 + 4
  if (memcpy ((char *) buf3 + 4, buf5, n + 6) != (char *) buf1 + 4
      || memcmp (buf1, "aBcdRSTUVWklmnopq\0", 19))
      || memcmp (buf1, "aBcdRSTUVWklmnopq\0", 19))
    abort ();
    abort ();
 
 
  /* This call has side-effects in dst, therefore no checking.  */
  /* This call has side-effects in dst, therefore no checking.  */
  if (__builtin___memcpy_chk ((char *) buf1 + ++i + 8, (char *) buf5 + 1,
  if (__builtin___memcpy_chk ((char *) buf1 + ++i + 8, (char *) buf5 + 1,
                              n + 1, os ((char *) buf1 + ++i + 8))
                              n + 1, os ((char *) buf1 + ++i + 8))
      != (char *) buf1 + 11
      != (char *) buf1 + 11
      || memcmp (buf1, "aBcdRSTUVWkSmnopq\0", 19)
      || memcmp (buf1, "aBcdRSTUVWkSmnopq\0", 19)
      || i != 3)
      || i != 3)
    abort ();
    abort ();
 
 
  if (memcpy ((char *) buf3 + 14, buf6, n + 2) != (char *) buf1 + 14
  if (memcpy ((char *) buf3 + 14, buf6, n + 2) != (char *) buf1 + 14
      || memcmp (buf1, "aBcdRSTUVWkSmnrsq\0", 19))
      || memcmp (buf1, "aBcdRSTUVWkSmnrsq\0", 19))
    abort ();
    abort ();
 
 
  i = 1;
  i = 1;
 
 
  /* These might be handled by store_by_pieces.  */
  /* These might be handled by store_by_pieces.  */
  if (memcpy (buf2, "ABCDEFGHI", 9) != buf2
  if (memcpy (buf2, "ABCDEFGHI", 9) != buf2
      || memcmp (buf2, "ABCDEFGHI\0", 11))
      || memcmp (buf2, "ABCDEFGHI\0", 11))
    abort ();
    abort ();
 
 
  if (memcpy (buf2, "abcdefghijklmnopq", 17) != buf2
  if (memcpy (buf2, "abcdefghijklmnopq", 17) != buf2
      || memcmp (buf2, "abcdefghijklmnopq\0", 19))
      || memcmp (buf2, "abcdefghijklmnopq\0", 19))
    abort ();
    abort ();
 
 
  if (__builtin_memcpy (buf4, "ABCDEF", 6) != buf2
  if (__builtin_memcpy (buf4, "ABCDEF", 6) != buf2
      || memcmp (buf2, "ABCDEFghijklmnopq\0", 19))
      || memcmp (buf2, "ABCDEFghijklmnopq\0", 19))
    abort ();
    abort ();
 
 
  if (__builtin_memcpy (buf4, "a", 1) != buf2
  if (__builtin_memcpy (buf4, "a", 1) != buf2
      || memcmp (buf2, "aBCDEFghijklmnopq\0", 19))
      || memcmp (buf2, "aBCDEFghijklmnopq\0", 19))
    abort ();
    abort ();
 
 
  if (memcpy (buf4 + 2, "bcd" + i++, 2) != buf2 + 2
  if (memcpy (buf4 + 2, "bcd" + i++, 2) != buf2 + 2
      || memcmp (buf2, "aBcdEFghijklmnopq\0", 19)
      || memcmp (buf2, "aBcdEFghijklmnopq\0", 19)
      || i != 2)
      || i != 2)
    abort ();
    abort ();
 
 
  /* These might be handled by move_by_pieces.  */
  /* These might be handled by move_by_pieces.  */
  if (memcpy (buf4 + 4, buf7, 6) != buf2 + 4
  if (memcpy (buf4 + 4, buf7, 6) != buf2 + 4
      || memcmp (buf2, "aBcdRSTUVWklmnopq\0", 19))
      || memcmp (buf2, "aBcdRSTUVWklmnopq\0", 19))
    abort ();
    abort ();
 
 
  /* Side effect.  */
  /* Side effect.  */
  if (__builtin___memcpy_chk (buf2 + i++ + 8, buf7 + 1, 1,
  if (__builtin___memcpy_chk (buf2 + i++ + 8, buf7 + 1, 1,
                              os (buf2 + i++ + 8))
                              os (buf2 + i++ + 8))
      != buf2 + 10
      != buf2 + 10
      || memcmp (buf2, "aBcdRSTUVWSlmnopq\0", 19)
      || memcmp (buf2, "aBcdRSTUVWSlmnopq\0", 19)
      || i != 3)
      || i != 3)
    abort ();
    abort ();
 
 
  if (memcpy (buf4 + 14, buf6, 2) != buf2 + 14
  if (memcpy (buf4 + 14, buf6, 2) != buf2 + 14
      || memcmp (buf2, "aBcdRSTUVWSlmnrsq\0", 19))
      || memcmp (buf2, "aBcdRSTUVWSlmnrsq\0", 19))
    abort ();
    abort ();
 
 
  __builtin_memcpy (buf4, "aBcdEFghijklmnopq\0", 19);
  __builtin_memcpy (buf4, "aBcdEFghijklmnopq\0", 19);
 
 
  /* These should be handled either by movmemendM or memcpy
  /* These should be handled either by movmemendM or memcpy
     call.  */
     call.  */
  if (memcpy (buf4 + 4, buf7, n + 6) != buf2 + 4
  if (memcpy (buf4 + 4, buf7, n + 6) != buf2 + 4
      || memcmp (buf2, "aBcdRSTUVWklmnopq\0", 19))
      || memcmp (buf2, "aBcdRSTUVWklmnopq\0", 19))
    abort ();
    abort ();
 
 
  /* Side effect.  */
  /* Side effect.  */
  if (__builtin___memcpy_chk (buf2 + i++ + 8, buf7 + 1, n + 1,
  if (__builtin___memcpy_chk (buf2 + i++ + 8, buf7 + 1, n + 1,
                              os (buf2 + i++ + 8))
                              os (buf2 + i++ + 8))
      != buf2 + 11
      != buf2 + 11
      || memcmp (buf2, "aBcdRSTUVWkSmnopq\0", 19)
      || memcmp (buf2, "aBcdRSTUVWkSmnopq\0", 19)
      || i != 4)
      || i != 4)
    abort ();
    abort ();
 
 
  if (memcpy (buf4 + 14, buf6, n + 2) != buf2 + 14
  if (memcpy (buf4 + 14, buf6, n + 2) != buf2 + 14
      || memcmp (buf2, "aBcdRSTUVWkSmnrsq\0", 19))
      || memcmp (buf2, "aBcdRSTUVWkSmnrsq\0", 19))
    abort ();
    abort ();
 
 
  if (chk_calls)
  if (chk_calls)
    abort ();
    abort ();
}
}
 
 
void
void
__attribute__((noinline))
__attribute__((noinline))
test2 (void)
test2 (void)
{
{
  long *x;
  long *x;
  char *y;
  char *y;
  int z;
  int z;
  __builtin_memcpy (buf5, "RSTUVWXYZ0123456789", 20);
  __builtin_memcpy (buf5, "RSTUVWXYZ0123456789", 20);
  __builtin_memcpy (buf7, "RSTUVWXYZ0123456789", 20);
  __builtin_memcpy (buf7, "RSTUVWXYZ0123456789", 20);
 __asm ("" : "=r" (x) : "0" (buf1));
 __asm ("" : "=r" (x) : "0" (buf1));
 __asm ("" : "=r" (y) : "0" (buf2));
 __asm ("" : "=r" (y) : "0" (buf2));
 __asm ("" : "=r" (z) : "0" (0));
 __asm ("" : "=r" (z) : "0" (0));
  test2_sub (x, y, "rstuvwxyz", z);
  test2_sub (x, y, "rstuvwxyz", z);
}
}
 
 
/* Test whether compile time checking is done where it should
/* Test whether compile time checking is done where it should
   and so is runtime object size checking.  */
   and so is runtime object size checking.  */
void
void
__attribute__((noinline))
__attribute__((noinline))
test3 (void)
test3 (void)
{
{
  struct A { char buf1[10]; char buf2[10]; } a;
  struct A { char buf1[10]; char buf2[10]; } a;
  char *r = l1 == 1 ? &a.buf1[5] : &a.buf2[4];
  char *r = l1 == 1 ? &a.buf1[5] : &a.buf2[4];
  char buf3[20];
  char buf3[20];
  int i;
  int i;
  size_t l;
  size_t l;
 
 
  /* The following calls should do runtime checking
  /* The following calls should do runtime checking
     - length is not known, but destination is.  */
     - length is not known, but destination is.  */
  chk_calls = 0;
  chk_calls = 0;
  memcpy (a.buf1 + 2, s3, l1);
  memcpy (a.buf1 + 2, s3, l1);
  memcpy (r, s3, l1 + 1);
  memcpy (r, s3, l1 + 1);
  r = l1 == 1 ? __builtin_alloca (4) : &a.buf2[7];
  r = l1 == 1 ? __builtin_alloca (4) : &a.buf2[7];
  memcpy (r, s2, l1 + 2);
  memcpy (r, s2, l1 + 2);
  memcpy (r + 2, s3, l1);
  memcpy (r + 2, s3, l1);
  r = buf3;
  r = buf3;
  for (i = 0; i < 4; ++i)
  for (i = 0; i < 4; ++i)
    {
    {
      if (i == l1 - 1)
      if (i == l1 - 1)
        r = &a.buf1[1];
        r = &a.buf1[1];
      else if (i == l1)
      else if (i == l1)
        r = &a.buf2[7];
        r = &a.buf2[7];
      else if (i == l1 + 1)
      else if (i == l1 + 1)
        r = &buf3[5];
        r = &buf3[5];
      else if (i == l1 + 2)
      else if (i == l1 + 2)
        r = &a.buf1[9];
        r = &a.buf1[9];
    }
    }
  memcpy (r, s2, l1);
  memcpy (r, s2, l1);
  if (chk_calls != 5)
  if (chk_calls != 5)
    abort ();
    abort ();
 
 
  /* Following have known destination and known length,
  /* Following have known destination and known length,
     so if optimizing certainly shouldn't result in the checking
     so if optimizing certainly shouldn't result in the checking
     variants.  */
     variants.  */
  chk_calls = 0;
  chk_calls = 0;
  memcpy (a.buf1 + 2, s3, 1);
  memcpy (a.buf1 + 2, s3, 1);
  memcpy (r, s3, 2);
  memcpy (r, s3, 2);
  r = l1 == 1 ? __builtin_alloca (4) : &a.buf2[7];
  r = l1 == 1 ? __builtin_alloca (4) : &a.buf2[7];
  memcpy (r, s2, 3);
  memcpy (r, s2, 3);
  r = buf3;
  r = buf3;
  l = 4;
  l = 4;
  for (i = 0; i < 4; ++i)
  for (i = 0; i < 4; ++i)
    {
    {
      if (i == l1 - 1)
      if (i == l1 - 1)
        r = &a.buf1[1], l = 2;
        r = &a.buf1[1], l = 2;
      else if (i == l1)
      else if (i == l1)
        r = &a.buf2[7], l = 3;
        r = &a.buf2[7], l = 3;
      else if (i == l1 + 1)
      else if (i == l1 + 1)
        r = &buf3[5], l = 4;
        r = &buf3[5], l = 4;
      else if (i == l1 + 2)
      else if (i == l1 + 2)
        r = &a.buf1[9], l = 1;
        r = &a.buf1[9], l = 1;
    }
    }
  memcpy (r, s2, 1);
  memcpy (r, s2, 1);
  /* Here, l is known to be at most 4 and __builtin_object_size (&buf3[16], 0)
  /* Here, l is known to be at most 4 and __builtin_object_size (&buf3[16], 0)
     is 4, so this doesn't need runtime checking.  */
     is 4, so this doesn't need runtime checking.  */
  memcpy (&buf3[16], s2, l);
  memcpy (&buf3[16], s2, l);
  if (chk_calls)
  if (chk_calls)
    abort ();
    abort ();
  chk_calls = 0;
  chk_calls = 0;
}
}
 
 
/* Test whether runtime and/or compile time checking catches
/* Test whether runtime and/or compile time checking catches
   buffer overflows.  */
   buffer overflows.  */
void
void
__attribute__((noinline))
__attribute__((noinline))
test4 (void)
test4 (void)
{
{
  struct A { char buf1[10]; char buf2[10]; } a;
  struct A { char buf1[10]; char buf2[10]; } a;
  char buf3[20];
  char buf3[20];
 
 
  chk_fail_allowed = 1;
  chk_fail_allowed = 1;
  /* Runtime checks.  */
  /* Runtime checks.  */
  if (__builtin_setjmp (chk_fail_buf) == 0)
  if (__builtin_setjmp (chk_fail_buf) == 0)
    {
    {
      memcpy (&a.buf2[9], s2, l1 + 1);
      memcpy (&a.buf2[9], s2, l1 + 1);
      abort ();
      abort ();
    }
    }
  if (__builtin_setjmp (chk_fail_buf) == 0)
  if (__builtin_setjmp (chk_fail_buf) == 0)
    {
    {
      memcpy (&a.buf2[7], s3, strlen (s3) + 1);
      memcpy (&a.buf2[7], s3, strlen (s3) + 1);
      abort ();
      abort ();
    }
    }
  /* This should be detectable at compile time already.  */
  /* This should be detectable at compile time already.  */
  if (__builtin_setjmp (chk_fail_buf) == 0)
  if (__builtin_setjmp (chk_fail_buf) == 0)
    {
    {
      memcpy (&buf3[19], "ab", 2);
      memcpy (&buf3[19], "ab", 2);
      abort ();
      abort ();
    }
    }
  chk_fail_allowed = 0;
  chk_fail_allowed = 0;
}
}
 
 
#ifndef MAX_OFFSET
#ifndef MAX_OFFSET
#define MAX_OFFSET (sizeof (long long))
#define MAX_OFFSET (sizeof (long long))
#endif
#endif
 
 
#ifndef MAX_COPY
#ifndef MAX_COPY
#define MAX_COPY (10 * sizeof (long long))
#define MAX_COPY (10 * sizeof (long long))
#endif
#endif
 
 
#ifndef MAX_EXTRA
#ifndef MAX_EXTRA
#define MAX_EXTRA (sizeof (long long))
#define MAX_EXTRA (sizeof (long long))
#endif
#endif
 
 
#define MAX_LENGTH (MAX_OFFSET + MAX_COPY + MAX_EXTRA)
#define MAX_LENGTH (MAX_OFFSET + MAX_COPY + MAX_EXTRA)
 
 
/* Use a sequence length that is not divisible by two, to make it more
/* Use a sequence length that is not divisible by two, to make it more
   likely to detect when words are mixed up.  */
   likely to detect when words are mixed up.  */
#define SEQUENCE_LENGTH 31
#define SEQUENCE_LENGTH 31
 
 
static union {
static union {
  char buf[MAX_LENGTH];
  char buf[MAX_LENGTH];
  long long align_int;
  long long align_int;
  long double align_fp;
  long double align_fp;
} u1, u2;
} u1, u2;
 
 
void
void
__attribute__((noinline))
__attribute__((noinline))
test5 (void)
test5 (void)
{
{
  int off1, off2, len, i;
  int off1, off2, len, i;
  char *p, *q, c;
  char *p, *q, c;
 
 
  for (off1 = 0; off1 < MAX_OFFSET; off1++)
  for (off1 = 0; off1 < MAX_OFFSET; off1++)
    for (off2 = 0; off2 < MAX_OFFSET; off2++)
    for (off2 = 0; off2 < MAX_OFFSET; off2++)
      for (len = 1; len < MAX_COPY; len++)
      for (len = 1; len < MAX_COPY; len++)
        {
        {
          for (i = 0, c = 'A'; i < MAX_LENGTH; i++, c++)
          for (i = 0, c = 'A'; i < MAX_LENGTH; i++, c++)
            {
            {
              u1.buf[i] = 'a';
              u1.buf[i] = 'a';
              if (c >= 'A' + SEQUENCE_LENGTH)
              if (c >= 'A' + SEQUENCE_LENGTH)
                c = 'A';
                c = 'A';
              u2.buf[i] = c;
              u2.buf[i] = c;
            }
            }
 
 
          p = memcpy (u1.buf + off1, u2.buf + off2, len);
          p = memcpy (u1.buf + off1, u2.buf + off2, len);
          if (p != u1.buf + off1)
          if (p != u1.buf + off1)
            abort ();
            abort ();
 
 
          q = u1.buf;
          q = u1.buf;
          for (i = 0; i < off1; i++, q++)
          for (i = 0; i < off1; i++, q++)
            if (*q != 'a')
            if (*q != 'a')
              abort ();
              abort ();
 
 
          for (i = 0, c = 'A' + off2; i < len; i++, q++, c++)
          for (i = 0, c = 'A' + off2; i < len; i++, q++, c++)
            {
            {
              if (c >= 'A' + SEQUENCE_LENGTH)
              if (c >= 'A' + SEQUENCE_LENGTH)
                c = 'A';
                c = 'A';
              if (*q != c)
              if (*q != c)
                abort ();
                abort ();
            }
            }
 
 
          for (i = 0; i < MAX_EXTRA; i++, q++)
          for (i = 0; i < MAX_EXTRA; i++, q++)
            if (*q != 'a')
            if (*q != 'a')
              abort ();
              abort ();
        }
        }
}
}
 
 
#define TESTSIZE 80
#define TESTSIZE 80
 
 
char srcb[TESTSIZE] __attribute__ ((aligned));
char srcb[TESTSIZE] __attribute__ ((aligned));
char dstb[TESTSIZE] __attribute__ ((aligned));
char dstb[TESTSIZE] __attribute__ ((aligned));
 
 
void
void
__attribute__((noinline))
__attribute__((noinline))
check (char *test, char *match, int n)
check (char *test, char *match, int n)
{
{
  if (memcmp (test, match, n))
  if (memcmp (test, match, n))
    abort ();
    abort ();
}
}
 
 
#define TN(n) \
#define TN(n) \
{ memset (dstb, 0, n); memcpy (dstb, srcb, n); check (dstb, srcb, n); }
{ memset (dstb, 0, n); memcpy (dstb, srcb, n); check (dstb, srcb, n); }
#define T(n) \
#define T(n) \
TN (n) \
TN (n) \
TN ((n) + 1) \
TN ((n) + 1) \
TN ((n) + 2) \
TN ((n) + 2) \
TN ((n) + 3)
TN ((n) + 3)
 
 
void
void
__attribute__((noinline))
__attribute__((noinline))
test6 (void)
test6 (void)
{
{
  int i;
  int i;
 
 
  chk_calls = 0;
  chk_calls = 0;
 
 
  for (i = 0; i < sizeof (srcb); ++i)
  for (i = 0; i < sizeof (srcb); ++i)
      srcb[i] = 'a' + i % 26;
      srcb[i] = 'a' + i % 26;
 
 
  T (0);
  T (0);
  T (4);
  T (4);
  T (8);
  T (8);
  T (12);
  T (12);
  T (16);
  T (16);
  T (20);
  T (20);
  T (24);
  T (24);
  T (28);
  T (28);
  T (32);
  T (32);
  T (36);
  T (36);
  T (40);
  T (40);
  T (44);
  T (44);
  T (48);
  T (48);
  T (52);
  T (52);
  T (56);
  T (56);
  T (60);
  T (60);
  T (64);
  T (64);
  T (68);
  T (68);
  T (72);
  T (72);
  T (76);
  T (76);
 
 
  /* All memcpy calls in this routine have constant arguments.  */
  /* All memcpy calls in this routine have constant arguments.  */
  if (chk_calls)
  if (chk_calls)
    abort ();
    abort ();
}
}
 
 
void
void
main_test (void)
main_test (void)
{
{
#ifndef __OPTIMIZE__
#ifndef __OPTIMIZE__
  /* Object size checking is only intended for -O[s123].  */
  /* Object size checking is only intended for -O[s123].  */
  return;
  return;
#endif
#endif
  __asm ("" : "=r" (l1) : "0" (l1));
  __asm ("" : "=r" (l1) : "0" (l1));
  test1 ();
  test1 ();
  test2 ();
  test2 ();
  test3 ();
  test3 ();
  test4 ();
  test4 ();
  test5 ();
  test5 ();
  test6 ();
  test6 ();
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.