This is the mail archive of the gcc-patches@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]

Re: static-after-extern tests vs. mips explicit relocs


Richard Henderson <rth@redhat.com> writes:
> >   - It removes a static qualifier from link_error() in string-opt-16.c.
> >     (This hunk was in the last patch too.)
> 
> While this is ok, we still have 
> 
>   static int memcmp (const void *s1, const void *s2, size_t len)
> 
> below.  Seems best to move it to the new harness as well.

OK.

> >   - 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.
> 
> Please do move it.  Seems trivial to do.

Yeah, it was.  Damn my laziness.

> >   - 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.
> 
> Hmm.  I think these tests should be moved to gcc.dg where we
> can specify { dg-do link }.  Then we don't have to care that
> we are overriding both _exit and _Exit (and so the program
> cannot run).

OK.

Here's an updated patch.  It's just a case of adding and removing
various files so I've only attached the "add" side.  Tested with &
without -fno-builtin on mipsel-linux-gnu, mips-sgi-irix6.5 &
i686-pc-linux-gnu.

Richard


	* gcc.c-torture/execute/builtins: New directory.
	* gcc.c-torture/execute/string-opt-{3,4,16,17,18,19}.c: Move into
	gcc.c-torture/execute/builtins.
	* gcc.c-torture/execute/string-opt-asm-{1,2}.c: Likewise.
	* gcc.c-torture/execute/builtin-noret-{1,2}.c: Move to...
	* gcc.dg/builtin-noret-{1,2}.c: ...here.  Turn into link-only tests.
	* gcc.dg/no-builtin-1.c: Move into gcc.c-torture/execute/builtins.

*** /dev/null	Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtins/abs-1.c	Sat May 10 07:57:48 2003
***************
*** 0 ****
--- 1,23 ----
+ /* Test for -fno-builtin-FUNCTION.  */
+ /* Origin: Joseph Myers <jsm28@cam.ac.uk>.  */
+ /* GCC normally handles abs and labs as built-in functions even without
+    optimization.  So test that with -fno-builtin-abs, labs is so handled
+    but abs isn't.  */
+ 
+ int abs_called = 0;
+ 
+ extern int abs (int);
+ extern long labs (long);
+ extern void abort (void);
+ extern void exit (int);
+ 
+ void
+ main_test (void)
+ {
+   if (labs (0) != 0)
+     abort ();
+   if (abs (0) != 0)
+     abort ();
+   if (!abs_called)
+     abort ();
+ }
*** /dev/null	Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtins/abs-1-lib.c	Sat May 10 08:32:24 2003
***************
*** 0 ****
--- 1,21 ----
+ extern int abs_called;
+ extern int inside_main;
+ 
+ /* The labs call should have been optimized, but the abs call
+    shouldn't have been.  */
+ 
+ int
+ abs (int x)
+ {
+   if (inside_main)
+     abs_called = 1;
+   return (x < 0 ? -x : x);
+ }
+ 
+ long
+ labs (long x)
+ {
+   if (inside_main)
+     abort ();
+   return (x < 0 ? -x : x);
+ }
*** /dev/null	Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtins/abs-1.x	Sat May 10 07:59:37 2003
***************
*** 0 ****
--- 1,2 ----
+ set additional_flags -fno-builtin-abs
+ 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/memcmp.c	Sat May 10 08:09:09 2003
***************
*** 0 ****
--- 1,21 ----
+ extern int inside_main;
+ 
+ int
+ memcmp (const void *s1, const void *s2, __SIZE_TYPE__ len)
+ {
+   const unsigned char *sp1, *sp2;
+ 
+ #ifdef __OPTIMIZE__
+   if (inside_main)
+     abort ();
+ #endif
+ 
+   sp1 = s1;
+   sp2 = s2;
+   while (len != 0 && *sp1 == *sp2)
+     sp1++, sp2++, len--;
+ 
+   if (len == 0)
+     return 0;
+   return *sp1 - *sp2;
+ }
*** /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-6.c	Sat May 10 08:16:20 2003
***************
*** 0 ****
--- 1,34 ----
+ /* Copyright (C) 2001  Free Software Foundation.
+ 
+    Ensure that builtin memcmp operations when all three arguments
+    are constant is optimized and performs correctly.  Taken from
+    PR optimize/3508.
+ 
+    Written by Roger Sayle, 12/26/2001.  */
+ 
+ extern void abort (void);
+ extern void link_error (void);
+ 
+ typedef __SIZE_TYPE__ size_t;
+ extern int memcmp (const void *, const void *, size_t);
+ 
+ void
+ main_test (void)
+ {
+   if (memcmp ("abcd", "efgh", 4) >= 0)
+     link_error ();
+   if (memcmp ("abcd", "abcd", 4) != 0)
+     link_error ();
+   if (memcmp ("efgh", "abcd", 4) <= 0)
+     link_error ();
+ }
+ 
+ #ifndef __OPTIMIZE__
+ /* When not optimizing, the above tests may generate references to
+    the function link_error, but should never actually call it.  */
+ void
+ link_error ()
+ {
+   abort ();
+ }
+ #endif
*** /dev/null	Thu Apr 11 15:25:15 2002
--- testsuite/gcc.c-torture/execute/builtins/string-6-lib.c	Sat May 10 08:09:41 2003
***************
*** 0 ****
--- 1 ----
+ #include "lib/memcmp.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);
+ }
*** /dev/null	Thu Apr 11 15:25:15 2002
--- testsuite/gcc.dg/builtin-noret-1.c	Sat May 10 07:51:09 2003
***************
*** 0 ****
--- 1,73 ----
+ /* Test for builtin noreturn attributes.  */
+ /* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+ /* { dg-do link } */
+ /* { dg-options -O2 } */
+ 
+ extern void abort (void);
+ extern void exit (int);
+ extern void _exit (int);
+ extern void _Exit (int);
+ 
+ extern void tabort (void);
+ extern void texit (void);
+ extern void t_exit (void);
+ extern void t_Exit (void);
+ 
+ extern void link_failure (void);
+ 
+ int
+ main (void)
+ {
+   volatile int i = 0;
+   if (i)
+     tabort ();
+   if (i)
+     texit ();
+   if (i)
+     t_exit ();
+   if (i)
+     t_Exit ();
+   exit (0);
+ }
+ 
+ void
+ tabort (void)
+ {
+   abort ();
+   link_failure ();
+ }
+ 
+ void
+ texit (void)
+ {
+   exit (1);
+   link_failure ();
+ }
+ 
+ void
+ t_exit (void)
+ {
+   _exit (1);
+   link_failure ();
+ }
+ 
+ /* Some non-Unix libcs might not have _exit.  */
+ void
+ _exit (int i)
+ {
+   abort ();
+ }
+ 
+ void
+ t_Exit (void)
+ {
+   _Exit (1);
+   link_failure ();
+ }
+ 
+ /* Some libcs might not have _Exit.  */
+ void
+ _Exit (int i)
+ {
+   abort ();
+ }
*** /dev/null	Thu Apr 11 15:25:15 2002
--- testsuite/gcc.dg/builtin-noret-2.c	Sat May 10 08:28:35 2003
***************
*** 0 ****
--- 1,73 ----
+ /* Test for builtin noreturn attributes when the visible declarations
+    are function-local.  Modified from builtin-noret-1.c by Zack Weinberg
+    <zack@codesourcery.com>.  */
+ /* { dg-do link } */
+ /* { dg-options -O2 } */
+ 
+ extern void tabort (void);
+ extern void texit (void);
+ extern void t_exit (void);
+ extern void t_Exit (void);
+ 
+ extern void link_failure (void);
+ 
+ int
+ main (void)
+ {
+   volatile int i = 0;
+   if (i)
+     tabort ();
+   if (i)
+     texit ();
+   if (i)
+     t_exit ();
+   if (i)
+     t_Exit ();
+   exit (0);
+ }
+ 
+ void
+ tabort (void)
+ {
+   extern void abort (void);
+   abort ();
+   link_failure ();
+ }
+ 
+ void
+ texit (void)
+ {
+   extern void exit (int);
+   exit (1);
+   link_failure ();
+ }
+ 
+ void
+ t_exit (void)
+ {
+   extern void _exit (int);
+   _exit (1);
+   link_failure ();
+ }
+ 
+ /* Some non-Unix libcs might not have _exit.  */
+ void
+ _exit (int i)
+ {
+   abort ();
+ }
+ 
+ void
+ t_Exit (void)
+ {
+   extern void _Exit (int);
+   _Exit (1);
+   link_failure ();
+ }
+ 
+ /* Some libcs might not have _Exit.  */
+ void
+ _Exit (int i)
+ {
+   abort ();
+ }


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