/* Copyright (C) 2003, 2004 Free Software Foundation.
|
/* Copyright (C) 2003, 2004 Free Software Foundation.
|
|
|
Ensure builtin memmove and bcopy perform correctly.
|
Ensure builtin memmove and bcopy perform correctly.
|
|
|
Written by Jakub Jelinek, 4/26/2003. */
|
Written by Jakub Jelinek, 4/26/2003. */
|
|
|
extern void abort (void);
|
extern void abort (void);
|
typedef __SIZE_TYPE__ size_t;
|
typedef __SIZE_TYPE__ size_t;
|
extern void *memmove (void *, const void *, size_t);
|
extern void *memmove (void *, const void *, size_t);
|
extern void bcopy (const void *, void *, size_t);
|
extern void bcopy (const void *, void *, size_t);
|
extern int memcmp (const void *, const void *, size_t);
|
extern int memcmp (const void *, const void *, size_t);
|
|
|
const char s1[] = "123";
|
const char s1[] = "123";
|
char p[32] = "";
|
char p[32] = "";
|
|
|
static const struct foo
|
static const struct foo
|
{
|
{
|
char *s;
|
char *s;
|
double d;
|
double d;
|
long l;
|
long l;
|
} foo[] =
|
} foo[] =
|
{
|
{
|
{ "hello world1", 3.14159, 101L },
|
{ "hello world1", 3.14159, 101L },
|
{ "hello world2", 3.14159, 102L },
|
{ "hello world2", 3.14159, 102L },
|
{ "hello world3", 3.14159, 103L },
|
{ "hello world3", 3.14159, 103L },
|
{ "hello world4", 3.14159, 104L },
|
{ "hello world4", 3.14159, 104L },
|
{ "hello world5", 3.14159, 105L },
|
{ "hello world5", 3.14159, 105L },
|
{ "hello world6", 3.14159, 106L }
|
{ "hello world6", 3.14159, 106L }
|
};
|
};
|
|
|
static const struct bar
|
static const struct bar
|
{
|
{
|
char *s;
|
char *s;
|
const struct foo f[3];
|
const struct foo f[3];
|
} bar[] =
|
} bar[] =
|
{
|
{
|
{
|
{
|
"hello world10",
|
"hello world10",
|
{
|
{
|
{ "hello1", 3.14159, 201L },
|
{ "hello1", 3.14159, 201L },
|
{ "hello2", 3.14159, 202L },
|
{ "hello2", 3.14159, 202L },
|
{ "hello3", 3.14159, 203L },
|
{ "hello3", 3.14159, 203L },
|
}
|
}
|
},
|
},
|
{
|
{
|
"hello world11",
|
"hello world11",
|
{
|
{
|
{ "hello4", 3.14159, 204L },
|
{ "hello4", 3.14159, 204L },
|
{ "hello5", 3.14159, 205L },
|
{ "hello5", 3.14159, 205L },
|
{ "hello6", 3.14159, 206L },
|
{ "hello6", 3.14159, 206L },
|
}
|
}
|
}
|
}
|
};
|
};
|
|
|
static const int baz[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
|
static const int baz[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
|
|
|
void
|
void
|
main_test (void)
|
main_test (void)
|
{
|
{
|
const char *s;
|
const char *s;
|
struct foo f1[sizeof foo/sizeof*foo];
|
struct foo f1[sizeof foo/sizeof*foo];
|
struct bar b1[sizeof bar/sizeof*bar];
|
struct bar b1[sizeof bar/sizeof*bar];
|
int bz[sizeof baz/sizeof*baz];
|
int bz[sizeof baz/sizeof*baz];
|
|
|
if (memmove (f1, foo, sizeof (foo)) != f1 || memcmp (f1, foo, sizeof (foo)))
|
if (memmove (f1, foo, sizeof (foo)) != f1 || memcmp (f1, foo, sizeof (foo)))
|
abort ();
|
abort ();
|
if (memmove (b1, bar, sizeof (bar)) != b1 || memcmp (b1, bar, sizeof (bar)))
|
if (memmove (b1, bar, sizeof (bar)) != b1 || memcmp (b1, bar, sizeof (bar)))
|
abort ();
|
abort ();
|
bcopy (baz, bz, sizeof (baz));
|
bcopy (baz, bz, sizeof (baz));
|
if (memcmp (bz, baz, sizeof (baz)))
|
if (memcmp (bz, baz, sizeof (baz)))
|
abort ();
|
abort ();
|
|
|
if (memmove (p, "abcde", 6) != p || memcmp (p, "abcde", 6))
|
if (memmove (p, "abcde", 6) != p || memcmp (p, "abcde", 6))
|
abort ();
|
abort ();
|
s = s1;
|
s = s1;
|
if (memmove (p + 2, ++s, 0) != p + 2 || memcmp (p, "abcde", 6) || s != s1 + 1)
|
if (memmove (p + 2, ++s, 0) != p + 2 || memcmp (p, "abcde", 6) || s != s1 + 1)
|
abort ();
|
abort ();
|
if (__builtin_memmove (p + 3, "", 1) != p + 3 || memcmp (p, "abc\0e", 6))
|
if (__builtin_memmove (p + 3, "", 1) != p + 3 || memcmp (p, "abc\0e", 6))
|
abort ();
|
abort ();
|
bcopy ("fghijk", p + 2, 4);
|
bcopy ("fghijk", p + 2, 4);
|
if (memcmp (p, "abfghi", 7))
|
if (memcmp (p, "abfghi", 7))
|
abort ();
|
abort ();
|
s = s1 + 1;
|
s = s1 + 1;
|
bcopy (s++, p + 1, 0);
|
bcopy (s++, p + 1, 0);
|
if (memcmp (p, "abfghi", 7) || s != s1 + 2)
|
if (memcmp (p, "abfghi", 7) || s != s1 + 2)
|
abort ();
|
abort ();
|
__builtin_bcopy ("ABCDE", p + 4, 1);
|
__builtin_bcopy ("ABCDE", p + 4, 1);
|
if (memcmp (p, "abfgAi", 7))
|
if (memcmp (p, "abfgAi", 7))
|
abort ();
|
abort ();
|
}
|
}
|
|
|