This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: static-after-extern tests vs. mips explicit relocs
Janis Johnson <janis187@us.ibm.com> writes:
> On Thu, May 08, 2003 at 11:00:19AM -0700, Richard Henderson wrote:
> > On Thu, May 08, 2003 at 06:28:16PM +0100, Richard Sandiford wrote:
> > > When the definitions were static, they didn't override the builtins.
> > > Now they do, so they're no longer builtins within main().
> >
> > Argh! The only solution is separate compilation then.
> > I'm not sure how to do that within the test framework...
>
> Tests that use compat.exp use separate compilation; see g++.dg/compat
> and gcc.dg/compat. The format of those tests is described in the
> internals manual, in sourcebuild.texi.
Thanks for the pointer. After trying various things, I think
it's probably easiest to stick with c-torture.exp in this case.
It can already handle multi-source tests (which was news to me)
and we only want to use the one compiler.
The patch below moves the problematic string-opt-* tests under the
control of a new harness, builtins.exp. Also:
- It removes a static qualifier from link_error() in string-opt-16.c.
(This hunk was in the last patch too.)
- It adds -mno-explicit-relocs to no-builtin-1.c for mips targets.
If this isn't acceptable, I can try adding a similar test to
builtins.exp.
- It adds -mno-explicit-relocs for builtin-noret-*.c. These tests
override _exit and _Exit, which I guess really have to be kept local.
And irix does need the _Exit definition.
(BTW, since the native irix linker doesn't complain about invalid
call16 relocs, and since this _Exit is never supposed to be called,
the test does actually pass with native ld. But it would fail to
link with GNU ld.)
Tested on mips-sgi-irix6.5, mipsel-linux-gnu & i686-pc-linux-gnu.
The tests pass when run normally and fail with -fno-builtin.
OK to install?
Richard
* gcc.c-torture/execute/builtins: New directory.
* gcc.c-torture/execute/string-opt-16.c (link_error): Make extern.
* gcc.c-torture/execute/string-opt-{3,4,17,18,19}.c: Move into
the new builtins test directory.
* gcc.c-torture/execute/string-opt-asm-{1,2}.c: Likewise.
* gcc.c-torture/execute/builtin-noret-{1,2}.x: New files.
* gcc.dg/no-builtin-1.c: Add -mno-explicit-relocs for mips targets.
Index: testsuite/gcc.c-torture/execute/string-opt-16.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.c-torture/execute/string-opt-16.c,v
retrieving revision 1.2
diff -c -d -p -F^[(a-zA-Z0-9_^#] -r1.2 string-opt-16.c
*** testsuite/gcc.c-torture/execute/string-opt-16.c 21 Jan 2003 19:43:53 -0000 1.2
--- testsuite/gcc.c-torture/execute/string-opt-16.c 9 May 2003 07:38:43 -0000
*************** #else
*** 38,44 ****
/* When not optimizing, the above tests may generate references to
the function link_error, but should never actually call it. */
__attribute__ ((noinline))
! static void
link_error ()
{
abort ();
--- 38,44 ----
/* When not optimizing, the above tests may generate references to
the function link_error, but should never actually call it. */
__attribute__ ((noinline))
! void
link_error ()
{
abort ();
Index: testsuite/gcc.dg/no-builtin-1.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/no-builtin-1.c,v
retrieving revision 1.1
diff -c -d -p -F^[(a-zA-Z0-9_^#] -r1.1 no-builtin-1.c
*** testsuite/gcc.dg/no-builtin-1.c 18 Nov 2001 03:30:57 -0000 1.1
--- testsuite/gcc.dg/no-builtin-1.c 9 May 2003 07:38:43 -0000
***************
*** 2,7 ****
--- 2,8 ----
/* Origin: Joseph Myers <jsm28@cam.ac.uk>. */
/* { dg-do run } */
/* { dg-options "-fno-builtin-abs" } */
+ /* { dg-options "-fno-builtin-abs -mno-explicit-relocs" { target mips*-*-* } } */
/* GCC normally handles abs and labs as built-in functions even without
optimization. So test that with -fno-builtin-abs, labs is so handled
*** /dev/null Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtin-noret-1.x Fri May 9 08:36:21 2003
***************
*** 0 ****
--- 1,4 ----
+ if {[istarget mips*-*-*]} {
+ set additional_flags -mno-explicit-relocs
+ }
+ return 0
*** /dev/null Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtin-noret-2.x Fri May 9 08:36:21 2003
***************
*** 0 ****
--- 1,4 ----
+ if {[istarget mips*-*-*]} {
+ set additional_flags -mno-explicit-relocs
+ }
+ return 0
*** /dev/null Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtins/builtins.exp Fri May 9 07:50:09 2003
***************
*** 0 ****
--- 1,24 ----
+ # This harness is for testing builtin support. Each test has two files:
+ #
+ # - foo.c defines the main testing function, main_test().
+ # - foo-lib.c implements the library functions that foo.c is testing.
+ #
+ # The functions in foo-lib.c will often want to abort on certain inputs.
+ # They can use the global variable inside_main to see whether they are
+ # being called from the test program or part of the common runtime.
+ #
+ # In many cases, the library functions will behave as normal at -O0
+ # and abort when optimisation is enabled. Such implementations should
+ # go into the lib/ directory so that they can be included by any test
+ # that needs them. They shouldn't call any external functions in case
+ # those functions were overridden too.
+
+ load_lib c-torture.exp
+
+ foreach src [lsort [find $srcdir/$subdir *.c]] {
+ if {![string match *-lib.c $src] && [runtest_file_p $runtests $src]} {
+ c-torture-execute [list $src \
+ [file root $src]-lib.c \
+ $srcdir/$subdir/lib/main.c]
+ }
+ }
*** /dev/null Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtins/lib/main.c Thu May 8 23:04:02 2003
***************
*** 0 ****
--- 1,11 ----
+ extern void main_test (void);
+ int inside_main;
+
+ int
+ main ()
+ {
+ inside_main = 1;
+ main_test ();
+ inside_main = 0;
+ return 0;
+ }
*** /dev/null Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtins/lib/memmove.c Fri May 9 07:52:11 2003
***************
*** 0 ****
--- 1,30 ----
+ extern int inside_main;
+
+ void *
+ memmove (void *dst, const void *src, __SIZE_TYPE__ n)
+ {
+ char *dstp;
+ const char *srcp;
+
+ #ifdef __OPTIMIZE__
+ if (inside_main)
+ abort ();
+ #endif
+
+ srcp = src;
+ dstp = dst;
+ if (srcp < dstp)
+ while (n-- != 0)
+ dstp[n] = srcp[n];
+ else
+ while (n-- != 0)
+ *dstp++ = *srcp++;
+
+ return dst;
+ }
+
+ void
+ bcopy (const void *src, void *dst, __SIZE_TYPE__ n)
+ {
+ memmove (dst, src, n);
+ }
*** /dev/null Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtins/lib/mempcpy.c Fri May 9 07:52:47 2003
***************
*** 0 ****
--- 1,20 ----
+ extern int inside_main;
+
+ void *
+ mempcpy (void *dst, const void *src, __SIZE_TYPE__ n)
+ {
+ const char *srcp;
+ char *dstp;
+
+ #ifdef __OPTIMIZE__
+ if (inside_main)
+ abort ();
+ #endif
+
+ srcp = src;
+ dstp = dst;
+ while (n-- != 0)
+ *dstp++ = *srcp++;
+
+ return dstp;
+ }
*** /dev/null Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtins/lib/stpcpy.c Thu May 8 23:10:27 2003
***************
*** 0 ****
--- 1,16 ----
+ extern int inside_main;
+
+ char *
+ stpcpy (char *dst, const char *src)
+ {
+ #ifdef __OPTIMIZE__
+ if (inside_main)
+ abort ();
+ #endif
+
+ while (*src != 0)
+ *dst++ = *src++;
+
+ *dst = 0;
+ return dst;
+ }
*** /dev/null Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtins/lib/strchr.c Fri May 9 07:53:31 2003
***************
*** 0 ****
--- 1,25 ----
+ extern int inside_main;
+
+ char *
+ strchr (const char *s, int c)
+ {
+ #ifdef __OPTIMIZE__
+ if (inside_main)
+ abort ();
+ #endif
+
+ for (;;)
+ {
+ if (*s == c)
+ return (char *) s;
+ if (*s == 0)
+ return 0;
+ s++;
+ }
+ }
+
+ char *
+ index (const char *s, int c)
+ {
+ return strchr (s, c);
+ }
*** /dev/null Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtins/lib/strcmp.c Thu May 8 23:21:06 2003
***************
*** 0 ****
--- 1,17 ----
+ extern int inside_main;
+
+ int
+ strcmp (const char *s1, const char *s2)
+ {
+ #ifdef __OPTIMIZE__
+ if (inside_main)
+ abort ();
+ #endif
+
+ while (*s1 != 0 && *s1 == *s2)
+ s1++, s2++;
+
+ if (*s1 == 0 || *s2 == 0)
+ return (unsigned char) *s1 - (unsigned char) *s2;
+ return *s1 - *s2;
+ }
*** /dev/null Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtins/lib/strlen.c Thu May 8 23:22:39 2003
***************
*** 0 ****
--- 1,18 ----
+ extern int inside_main;
+
+ __SIZE_TYPE__
+ strlen (const char *s)
+ {
+ __SIZE_TYPE__ i;
+
+ #ifdef __OPTIMIZE__
+ if (inside_main)
+ abort ();
+ #endif
+
+ i = 0;
+ while (s[i] != 0)
+ i++;
+
+ return i;
+ }
*** /dev/null Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtins/lib/strrchr.c Fri May 9 07:54:49 2003
***************
*** 0 ****
--- 1,29 ----
+ extern int inside_main;
+
+ char *
+ strrchr (const char *s, int c)
+ {
+ __SIZE_TYPE__ i;
+
+ #ifdef __OPTIMIZE__
+ if (inside_main)
+ abort ();
+ #endif
+
+ i = 0;
+ while (s[i] != 0)
+ i++;
+
+ do
+ if (s[i] == c)
+ return (char *) s + i;
+ while (i-- != 0);
+
+ return 0;
+ }
+
+ char *
+ rindex (const char *s, int c)
+ {
+ return strrchr (s, c);
+ }
*** /dev/null Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtins/string-1.c Fri May 9 07:55:43 2003
***************
*** 0 ****
--- 1,87 ----
+ /* Copyright (C) 2000, 2003 Free Software Foundation.
+
+ Ensure all expected transformations of builtin strlen, strcmp,
+ strrchr and rindex occur and perform correctly.
+
+ Written by Jakub Jelinek, 11/7/2000. */
+
+ extern void abort (void);
+ extern __SIZE_TYPE__ strlen (const char *);
+ extern int strcmp (const char *, const char *);
+ extern char *strrchr (const char *, int);
+ extern char *rindex (const char *, int);
+
+ int x = 6;
+ char *bar = "hi world";
+
+ void
+ main_test (void)
+ {
+ const char *const foo = "hello world";
+
+ if (strlen (foo) != 11)
+ abort ();
+ if (strlen (foo + 4) != 7)
+ abort ();
+ if (strlen (foo + (x++ & 7)) != 5)
+ abort ();
+ if (x != 7)
+ abort ();
+ if (strcmp (foo, "hello") <= 0)
+ abort ();
+ if (strcmp (foo + 2, "llo") <= 0)
+ abort ();
+ if (strcmp (foo, foo) != 0)
+ abort ();
+ if (strcmp (foo, "hello world ") >= 0)
+ abort ();
+ if (strcmp (foo + 10, "dx") >= 0)
+ abort ();
+ if (strcmp (10 + foo, "dx") >= 0)
+ abort ();
+ if (strcmp (bar, "") <= 0)
+ abort ();
+ if (strcmp ("", bar) >= 0)
+ abort ();
+ if (strcmp (bar+8, "") != 0)
+ abort ();
+ if (strcmp ("", bar+8) != 0)
+ abort ();
+ if (strcmp (bar+(--x), "") <= 0 || x != 6)
+ abort ();
+ if (strcmp ("", bar+(++x)) >= 0 || x != 7)
+ abort ();
+ if (strrchr (foo, 'x'))
+ abort ();
+ if (strrchr (foo, 'o') != foo + 7)
+ abort ();
+ if (strrchr (foo, 'e') != foo + 1)
+ abort ();
+ if (strrchr (foo + 3, 'e'))
+ abort ();
+ if (strrchr (foo, '\0') != foo + 11)
+ abort ();
+ if (strrchr (bar, '\0') != bar + 8)
+ abort ();
+ if (strrchr (bar + 4, '\0') != bar + 8)
+ abort ();
+ if (strrchr (bar + (x++ & 3), '\0') != bar + 8)
+ abort ();
+ if (x != 8)
+ abort ();
+ /* Test only one instance of rindex since the code path is the same
+ as that of strrchr. */
+ if (rindex ("hello", 'z') != 0)
+ abort ();
+
+ /* Test at least one instance of the __builtin_ style. We do this
+ to ensure that it works and that the prototype is correct. */
+ if (__builtin_rindex (foo, 'o') != foo + 7)
+ abort ();
+ if (__builtin_strrchr (foo, 'o') != foo + 7)
+ abort ();
+ if (__builtin_strlen (foo) != 11)
+ abort ();
+ if (__builtin_strcmp (foo, "hello") <= 0)
+ abort ();
+ }
*** /dev/null Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtins/string-1-lib.c Thu May 8 22:18:36 2003
***************
*** 0 ****
--- 1,3 ----
+ #include "lib/strrchr.c"
+ #include "lib/strlen.c"
+ #include "lib/strcmp.c"
*** /dev/null Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtins/string-2.c Fri May 9 07:55:57 2003
***************
*** 0 ****
--- 1,36 ----
+ /* Copyright (C) 2000, 2003 Free Software Foundation.
+
+ Ensure all expected transformations of builtin strchr and index
+ occur and perform correctly.
+
+ Written by Jakub Jelinek, 11/7/2000. */
+
+ extern void abort (void);
+ extern char *strchr (const char *, int);
+ extern char *index (const char *, int);
+
+ void
+ main_test (void)
+ {
+ const char *const foo = "hello world";
+
+ if (strchr (foo, 'x'))
+ abort ();
+ if (strchr (foo, 'o') != foo + 4)
+ abort ();
+ if (strchr (foo + 5, 'o') != foo + 7)
+ abort ();
+ if (strchr (foo, '\0') != foo + 11)
+ abort ();
+ /* Test only one instance of index since the code path is the same
+ as that of strchr. */
+ if (index ("hello", 'z') != 0)
+ abort ();
+
+ /* Test at least one instance of the __builtin_ style. We do this
+ to ensure that it works and that the prototype is correct. */
+ if (__builtin_strchr (foo, 'o') != foo + 4)
+ abort ();
+ if (__builtin_index (foo, 'o') != foo + 4)
+ abort ();
+ }
*** /dev/null Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtins/string-2-lib.c Thu May 8 22:41:18 2003
***************
*** 0 ****
--- 1 ----
+ #include "lib/strchr.c"
*** /dev/null Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtins/string-3.c Fri May 9 07:56:05 2003
***************
*** 0 ****
--- 1,36 ----
+ /* Copyright (C) 2002, 2003 Free Software Foundation.
+
+ Ensure that builtin memset operations for constant length and
+ non-constant assigned value don't cause compiler problems.
+
+ Written by Roger Sayle, 21 April 2002. */
+
+ extern void abort (void);
+ typedef __SIZE_TYPE__ size_t;
+ extern void *memset (void *, int, size_t);
+
+ char buffer[32];
+ int argc = 1;
+
+ void
+ main_test (void)
+ {
+ memset (buffer, argc, 0);
+ memset (buffer, argc, 1);
+ memset (buffer, argc, 2);
+ memset (buffer, argc, 3);
+ memset (buffer, argc, 4);
+ memset (buffer, argc, 5);
+ memset (buffer, argc, 6);
+ memset (buffer, argc, 7);
+ memset (buffer, argc, 8);
+ memset (buffer, argc, 9);
+ memset (buffer, argc, 10);
+ memset (buffer, argc, 11);
+ memset (buffer, argc, 12);
+ memset (buffer, argc, 13);
+ memset (buffer, argc, 14);
+ memset (buffer, argc, 15);
+ memset (buffer, argc, 16);
+ memset (buffer, argc, 17);
+ }
*** /dev/null Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtins/string-3-lib.c Fri May 9 00:42:38 2003
***************
*** 0 ****
--- 1,17 ----
+ extern int inside_main;
+
+ void *
+ memset (void *dst, int c, __SIZE_TYPE__ n)
+ {
+ /* Single-byte memsets should be done inline when optimisation
+ is enabled. */
+ #ifdef __OPTIMIZE__
+ if (inside_main && n < 2)
+ abort ();
+ #endif
+
+ while (n-- != 0)
+ n[(char *) dst] = c;
+
+ return dst;
+ }
*** /dev/null Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtins/string-4.c Thu May 8 23:01:06 2003
***************
*** 0 ****
--- 1,78 ----
+ /* Copyright (C) 2003 Free Software Foundation.
+
+ Ensure builtin mempcpy and stpcpy perform correctly.
+
+ Written by Kaveh Ghazi, 4/11/2003. */
+
+ extern void abort (void);
+ extern char *strcpy (char *, const char *);
+ extern char *stpcpy (char *, const char *);
+ typedef __SIZE_TYPE__ size_t;
+ extern size_t strlen(const char *);
+ extern void *memcpy (void *, const void *, size_t);
+ extern void *mempcpy (void *, const void *, size_t);
+ extern int memcmp (const void *, const void *, size_t);
+
+ const char s1[] = "123";
+ char p[32] = "";
+ char *s2 = "defg";
+ char *s3 = "FGH";
+ size_t l1 = 1;
+
+ void
+ main_test (void)
+ {
+ int i;
+ const char *s;
+
+ if (stpcpy (p, "abcde") != p + 5 || memcmp (p, "abcde", 6))
+ abort ();
+ if (stpcpy (p + 16, "vwxyz" + 1) != p + 16 + 4 || memcmp (p + 16, "wxyz", 5))
+ abort ();
+ if (stpcpy (p + 1, "") != p + 1 + 0 || memcmp (p, "a\0cde", 6))
+ abort ();
+ if (stpcpy (p + 3, "fghij") != p + 3 + 5 || memcmp (p, "a\0cfghij", 9))
+ abort ();
+ if (mempcpy (p, "ABCDE", 6) != p + 6 || memcmp (p, "ABCDE", 6))
+ abort ();
+ if (mempcpy (p + 16, "VWX" + 1, 2) != p + 16 + 2 || memcmp (p + 16, "WXyz", 5))
+ abort ();
+ if (mempcpy (p + 1, "", 1) != p + 1 + 1 || memcmp (p, "A\0CDE", 6))
+ abort ();
+ if (mempcpy (p + 3, "FGHI", 4) != p + 3 + 4 || memcmp (p, "A\0CFGHIj", 9))
+ abort ();
+
+ i = 8;
+ memcpy (p + 20, "qrstu", 6);
+ if (stpcpy ((i++, p + 20 + 1), "23") != (p + 20 + 1 + 2) || i != 9 || memcmp (p + 20, "q23\0u", 6))
+ abort ();
+
+ s = s1; i = 3;
+ memcpy (p + 25, "QRSTU", 6);
+ if (mempcpy (p + 25 + 1, s++, i++) != (p + 25 + 1 + 3) || i != 4 || s != s1 + 1 || memcmp (p + 25, "Q123U", 6))
+ abort ();
+
+ if (stpcpy (stpcpy (p, "ABCD"), "EFG") != p + 7 || memcmp (p, "ABCDEFG", 8))
+ abort();
+ if (mempcpy (mempcpy (p, "abcdEFG", 4), "efg", 4) != p + 8 || memcmp (p, "abcdefg", 8))
+ abort();
+
+ /* Test at least one instance of the __builtin_ style. We do this
+ to ensure that it works and that the prototype is correct. */
+ if (__builtin_stpcpy (p, "abcde") != p + 5 || memcmp (p, "abcde", 6))
+ abort ();
+ if (__builtin_mempcpy (p, "ABCDE", 6) != p + 6 || memcmp (p, "ABCDE", 6))
+ abort ();
+
+ /* If the result of stpcpy/mempcpy is ignored, gcc should use
+ strcpy/memcpy. */
+ stpcpy (p + 3, s2);
+ if (memcmp (p, "ABCdefg", 8))
+ abort ();
+ mempcpy (p + 5, s3, 1);
+ if (memcmp (p, "ABCdeFg", 8))
+ abort ();
+ mempcpy (p + 6, s3 + 1, l1);
+ if (memcmp (p, "ABCdeFG", 8))
+ abort ();
+ }
*** /dev/null Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtins/string-4-lib.c Thu May 8 22:45:30 2003
***************
*** 0 ****
--- 1,2 ----
+ #include "lib/stpcpy.c"
+ #include "lib/mempcpy.c"
*** /dev/null Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtins/string-5.c Thu May 8 22:53:20 2003
***************
*** 0 ****
--- 1,90 ----
+ /* Copyright (C) 2003 Free Software Foundation.
+
+ Ensure builtin memmove and bcopy perform correctly.
+
+ Written by Jakub Jelinek, 4/26/2003. */
+
+ extern void abort (void);
+ typedef __SIZE_TYPE__ size_t;
+ extern void *memmove (void *, const void *, size_t);
+ extern void bcopy (const void *, void *, size_t);
+ extern int memcmp (const void *, const void *, size_t);
+
+ const char s1[] = "123";
+ char p[32] = "";
+
+ static const struct foo
+ {
+ char *s;
+ double d;
+ long l;
+ } foo[] =
+ {
+ { "hello world1", 3.14159, 101L },
+ { "hello world2", 3.14159, 102L },
+ { "hello world3", 3.14159, 103L },
+ { "hello world4", 3.14159, 104L },
+ { "hello world5", 3.14159, 105L },
+ { "hello world6", 3.14159, 106L }
+ };
+
+ static const struct bar
+ {
+ char *s;
+ const struct foo f[3];
+ } bar[] =
+ {
+ {
+ "hello world10",
+ {
+ { "hello1", 3.14159, 201L },
+ { "hello2", 3.14159, 202L },
+ { "hello3", 3.14159, 203L },
+ }
+ },
+ {
+ "hello world11",
+ {
+ { "hello4", 3.14159, 204L },
+ { "hello5", 3.14159, 205L },
+ { "hello6", 3.14159, 206L },
+ }
+ }
+ };
+
+ static const int baz[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
+
+ void
+ main_test (void)
+ {
+ const char *s;
+ struct foo f1[sizeof foo/sizeof*foo];
+ struct bar b1[sizeof bar/sizeof*bar];
+ int bz[sizeof baz/sizeof*baz];
+
+ if (memmove (f1, foo, sizeof (foo)) != f1 || memcmp (f1, foo, sizeof(foo)))
+ abort();
+ if (memmove (b1, bar, sizeof (bar)) != b1 || memcmp (b1, bar, sizeof(bar)))
+ abort();
+ bcopy (baz, bz, sizeof (baz));
+ if (memcmp (bz, baz, sizeof(baz)))
+ abort();
+
+ if (memmove (p, "abcde", 6) != p || memcmp (p, "abcde", 6))
+ abort ();
+ s = s1;
+ if (memmove (p + 2, ++s, 0) != p + 2 || memcmp (p, "abcde", 6) || s != s1 + 1)
+ abort ();
+ if (__builtin_memmove (p + 3, "", 1) != p + 3 || memcmp (p, "abc\0e", 6))
+ abort ();
+ bcopy ("fghijk", p + 2, 4);
+ if (memcmp (p, "abfghi", 7))
+ abort ();
+ s = s1 + 1;
+ bcopy (s++, p + 1, 0);
+ if (memcmp (p, "abfghi", 7) || s != s1 + 2)
+ abort ();
+ __builtin_bcopy ("ABCDE", p + 4, 1);
+ if (memcmp (p, "abfgAi", 7))
+ abort ();
+ }
*** /dev/null Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtins/string-5-lib.c Thu May 8 22:44:33 2003
***************
*** 0 ****
--- 1 ----
+ #include "lib/memmove.c"
*** /dev/null Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtins/string-asm-1.c Fri May 9 08:08:33 2003
***************
*** 0 ****
--- 1,41 ----
+ /* Copyright (C) 2000, 2003 Free Software Foundation.
+
+ Ensure all expected transformations of builtin strstr occur and
+ perform correctly in presence of redirect. */
+
+ typedef __SIZE_TYPE__ size_t;
+ extern void abort (void);
+ extern char *strstr (const char *, const char *)
+ __asm ("my_strstr");
+
+ const char *p = "rld", *q = "hello world";
+
+ void
+ main_test (void)
+ {
+ const char *const foo = "hello world";
+
+ if (strstr (foo, "") != foo)
+ abort ();
+ if (strstr (foo + 4, "") != foo + 4)
+ abort ();
+ if (strstr (foo, "h") != foo)
+ abort ();
+ if (strstr (foo, "w") != foo + 6)
+ abort ();
+ if (strstr (foo + 6, "o") != foo + 7)
+ abort ();
+ if (strstr (foo + 1, "world") != foo + 6)
+ abort ();
+ if (strstr (foo + 2, p) != foo + 8)
+ abort ();
+ if (strstr (q, "") != q)
+ abort ();
+ if (strstr (q + 1, "o") != q + 4)
+ abort ();
+
+ /* Test at least one instance of the __builtin_ style. We do this
+ to ensure that it works and that the prototype is correct. */
+ if (__builtin_strstr (foo + 1, "world") != foo + 6)
+ abort ();
+ }
*** /dev/null Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtins/string-asm-1-lib.c Fri May 9 00:44:07 2003
***************
*** 0 ****
--- 1,31 ----
+ extern int inside_main;
+ extern const char *p;
+
+ char *
+ my_strstr (const char *s1, const char *s2)
+ {
+ __SIZE_TYPE__ len = strlen (s2);
+
+ #ifdef __OPTIMIZE__
+ /* If optimizing, we should be called only in the strstr (foo + 2, p)
+ case. All other cases should be optimized. */
+ if (inside_main)
+ if (s2 != p || strcmp (s1, "hello world" + 2) != 0)
+ abort ();
+ #endif
+ if (len == 0)
+ return (char *) s1;
+ for (s1 = strchr (s1, *s2); s1; s1 = strchr (s1 + 1, *s2))
+ if (strncmp (s1, s2, len) == 0)
+ return (char *) s1;
+ return (char *) 0;
+ }
+
+ char *
+ strstr (const char *s1, const char *s2)
+ {
+ if (inside_main)
+ abort ();
+
+ return my_strstr (s1, s2);
+ }
*** /dev/null Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtins/string-asm-2.c Fri May 9 00:31:31 2003
***************
*** 0 ****
--- 1,43 ----
+ /* Copyright (C) 2003 Free Software Foundation.
+
+ Test memcpy and memset in presence of redirect. */
+
+ typedef __SIZE_TYPE__ size_t;
+ extern void abort (void);
+ extern void *memcpy (void *, const void *, size_t)
+ __asm ("my_memcpy");
+ extern void bcopy (const void *, void *, size_t)
+ __asm ("my_bcopy");
+ extern void *memset (void *, int, size_t)
+ __asm ("my_memset");
+ extern void bzero (void *, size_t)
+ __asm ("my_bzero");
+ extern int memcmp (const void *, const void *, size_t);
+
+ struct A { char c[32]; } a = { "foobar" };
+ char x[64] = "foobar", y[64];
+ int i = 39, j = 6, k = 4;
+
+ void
+ main_test (void)
+ {
+ struct A b = a;
+ struct A c = { { 'x' } };
+
+ if (memcmp (b.c, x, 32) || c.c[0] != 'x' || memcmp (c.c + 1, x + 32, 31))
+ abort ();
+ if (__builtin_memcpy (y, x, i) != y || memcmp (x, y, 64))
+ abort ();
+ if (memcpy (y + 6, x, j) != y + 6
+ || memcmp (x, y, 6) || memcmp (x, y + 6, 58))
+ abort ();
+ if (__builtin_memset (y + 2, 'X', k) != y + 2
+ || memcmp (y, "foXXXXfoobar", 13))
+ abort ();
+ bcopy (y + 1, y + 2, 6);
+ if (memcmp (y, "fooXXXXfobar", 13))
+ abort ();
+ __builtin_bzero (y + 4, 2);
+ if (memcmp (y, "fooX\0\0Xfobar", 13))
+ abort ();
+ }
*** /dev/null Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtins/string-asm-2-lib.c Fri May 9 00:33:49 2003
***************
*** 0 ****
--- 1,76 ----
+ extern int inside_main;
+ typedef __SIZE_TYPE__ size_t;
+
+ #define TEST_ABORT if (inside_main) abort()
+
+ void *
+ my_memcpy (void *d, const void *s, size_t n)
+ {
+ char *dst = (char *) d;
+ const char *src = (const char *) s;
+ while (n--)
+ *dst++ = *src++;
+ return (char *) d;
+ }
+
+ void
+ my_bcopy (const void *s, void *d, size_t n)
+ {
+ char *dst = (char *) d;
+ const char *src = (const char *) s;
+ if (src >= dst)
+ while (n--)
+ *dst++ = *src++;
+ else
+ {
+ dst += n;
+ src += n;
+ while (n--)
+ *--dst = *--src;
+ }
+ }
+
+ void *
+ my_memset (void *d, int c, size_t n)
+ {
+ char *dst = (char *) d;
+ while (n--)
+ *dst++ = c;
+ return (char *) d;
+ }
+
+ void
+ my_bzero (void *d, size_t n)
+ {
+ char *dst = (char *) d;
+ while (n--)
+ *dst++ = '\0';
+ }
+
+ void *
+ memcpy (void *d, const void *s, size_t n)
+ {
+ TEST_ABORT;
+ return my_memcpy (d, s, n);
+ }
+
+ void
+ bcopy (const void *s, void *d, size_t n)
+ {
+ TEST_ABORT;
+ my_bcopy (s, d, n);
+ }
+
+ void *
+ memset (void *d, int c, size_t n)
+ {
+ TEST_ABORT;
+ return my_memset (d, c, n);
+ }
+
+ void
+ bzero (void *d, size_t n)
+ {
+ TEST_ABORT;
+ my_bzero (d, n);
+ }