aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.c-torture
diff options
context:
space:
mode:
authorZack Weinberg <zack@codesourcery.com>2004-07-03 02:16:50 +0000
committerZack Weinberg <zack@gcc.gnu.org>2004-07-03 02:16:50 +0000
commit50c6431753ab7961b4330c5f3c7e611ad81e9178 (patch)
tree8ae3364380b62899fdce8dab24912fcca4a476d3 /gcc/testsuite/gcc.c-torture
parente1e93ad8abcabbefa292506d8ae08dd66f9011a2 (diff)
downloadgcc-50c6431753ab7961b4330c5f3c7e611ad81e9178.zip
gcc-50c6431753ab7961b4330c5f3c7e611ad81e9178.tar.gz
gcc-50c6431753ab7961b4330c5f3c7e611ad81e9178.tar.bz2
* gcc.c-torture/execute/builtin-abs-1.c
* gcc.c-torture/execute/builtin-abs-2.c * gcc.c-torture/execute/builtin-complex-1.c * gcc.c-torture/execute/builtins/string-1-lib.c * gcc.c-torture/execute/builtins/string-1.c * gcc.c-torture/execute/builtins/string-2-lib.c * gcc.c-torture/execute/builtins/string-2.c * gcc.c-torture/execute/builtins/string-3-lib.c * gcc.c-torture/execute/builtins/string-3.c * gcc.c-torture/execute/builtins/string-4-lib.c * gcc.c-torture/execute/builtins/string-4.c * gcc.c-torture/execute/builtins/string-5-lib.c * gcc.c-torture/execute/builtins/string-5.c * gcc.c-torture/execute/builtins/string-6-lib.c * gcc.c-torture/execute/builtins/string-6.c * gcc.c-torture/execute/builtins/string-7-lib.c * gcc.c-torture/execute/builtins/string-7.c * gcc.c-torture/execute/builtins/string-8-lib.c * gcc.c-torture/execute/builtins/string-8.c * gcc.c-torture/execute/builtins/string-9-lib.c * gcc.c-torture/execute/builtins/string-9.c * gcc.c-torture/execute/builtins/string-asm-1-lib.c * gcc.c-torture/execute/builtins/string-asm-1.c * gcc.c-torture/execute/builtins/string-asm-2-lib.c * gcc.c-torture/execute/builtins/string-asm-2.c * gcc.c-torture/execute/stdio-opt-1.c * gcc.c-torture/execute/stdio-opt-2.c * gcc.c-torture/execute/stdio-opt-3.c * gcc.c-torture/execute/string-opt-1.c * gcc.c-torture/execute/string-opt-10.c * gcc.c-torture/execute/string-opt-11.c * gcc.c-torture/execute/string-opt-12.c * gcc.c-torture/execute/string-opt-13.c * gcc.c-torture/execute/string-opt-14.c * gcc.c-torture/execute/string-opt-15.c * gcc.c-torture/execute/string-opt-16.c * gcc.c-torture/execute/string-opt-2.c * gcc.c-torture/execute/string-opt-6.c * gcc.c-torture/execute/string-opt-7.c * gcc.c-torture/execute/string-opt-8.c: Replace with ... * gcc.c-torture/execute/builtins/abs-2.c * gcc.c-torture/execute/builtins/abs-3.c * gcc.c-torture/execute/builtins/complex-1.c * gcc.c-torture/execute/builtins/fprintf.c * gcc.c-torture/execute/builtins/fputs.c * gcc.c-torture/execute/builtins/memcmp.c * gcc.c-torture/execute/builtins/memmove.c * gcc.c-torture/execute/builtins/memops-asm.c * gcc.c-torture/execute/builtins/mempcpy-2.c * gcc.c-torture/execute/builtins/mempcpy.c * gcc.c-torture/execute/builtins/memset.c * gcc.c-torture/execute/builtins/printf.c * gcc.c-torture/execute/builtins/sprintf.c * gcc.c-torture/execute/builtins/strcat.c * gcc.c-torture/execute/builtins/strchr.c * gcc.c-torture/execute/builtins/strcmp.c * gcc.c-torture/execute/builtins/strcpy.c * gcc.c-torture/execute/builtins/strcspn.c * gcc.c-torture/execute/builtins/strlen-2.c * gcc.c-torture/execute/builtins/strlen.c * gcc.c-torture/execute/builtins/strncat.c * gcc.c-torture/execute/builtins/strncmp-2.c * gcc.c-torture/execute/builtins/strncmp.c * gcc.c-torture/execute/builtins/strncpy.c * gcc.c-torture/execute/builtins/strpbrk.c * gcc.c-torture/execute/builtins/strpcpy-2.c * gcc.c-torture/execute/builtins/strpcpy.c * gcc.c-torture/execute/builtins/strrchr.c * gcc.c-torture/execute/builtins/strspn.c * gcc.c-torture/execute/builtins/strstr-asm.c * gcc.c-torture/execute/builtins/strstr.c: ... these new files. * gcc.c-torture/execute/builtins/abs-2-lib.c * gcc.c-torture/execute/builtins/abs-3-lib.c * gcc.c-torture/execute/builtins/complex-1-lib.c * gcc.c-torture/execute/builtins/fprintf-lib.c * gcc.c-torture/execute/builtins/fputs-lib.c * gcc.c-torture/execute/builtins/memcmp-lib.c * gcc.c-torture/execute/builtins/memmove-lib.c * gcc.c-torture/execute/builtins/memops-asm-lib.c * gcc.c-torture/execute/builtins/mempcpy-2-lib.c * gcc.c-torture/execute/builtins/mempcpy-lib.c * gcc.c-torture/execute/builtins/memset-lib.c * gcc.c-torture/execute/builtins/printf-lib.c * gcc.c-torture/execute/builtins/sprintf-lib.c * gcc.c-torture/execute/builtins/strcat-lib.c * gcc.c-torture/execute/builtins/strchr-lib.c * gcc.c-torture/execute/builtins/strcmp-lib.c * gcc.c-torture/execute/builtins/strcpy-lib.c * gcc.c-torture/execute/builtins/strcspn-lib.c * gcc.c-torture/execute/builtins/strlen-2-lib.c * gcc.c-torture/execute/builtins/strlen-lib.c * gcc.c-torture/execute/builtins/strncat-lib.c * gcc.c-torture/execute/builtins/strncmp-2-lib.c * gcc.c-torture/execute/builtins/strncmp-lib.c * gcc.c-torture/execute/builtins/strncpy-lib.c * gcc.c-torture/execute/builtins/strpbrk-lib.c * gcc.c-torture/execute/builtins/strpcpy-2-lib.c * gcc.c-torture/execute/builtins/strpcpy-lib.c * gcc.c-torture/execute/builtins/strrchr-lib.c * gcc.c-torture/execute/builtins/strspn-lib.c * gcc.c-torture/execute/builtins/strstr-asm-lib.c * gcc.c-torture/execute/builtins/strstr-lib.c * gcc.c-torture/execute/builtins/lib/abs.c * gcc.c-torture/execute/builtins/lib/fprintf.c * gcc.c-torture/execute/builtins/lib/memset.c * gcc.c-torture/execute/builtins/lib/printf.c * gcc.c-torture/execute/builtins/lib/sprintf.c * gcc.c-torture/execute/builtins/lib/strcpy.c * gcc.c-torture/execute/builtins/lib/strcspn.c * gcc.c-torture/execute/builtins/lib/strncat.c * gcc.c-torture/execute/builtins/lib/strncmp.c * gcc.c-torture/execute/builtins/lib/strncpy.c * gcc.c-torture/execute/builtins/lib/strpbrk.c * gcc.c-torture/execute/builtins/lib/strspn.c * gcc.c-torture/execute/builtins/lib/strstr.c: New files containing support routines. * gcc.c-torture/execute/builtins/abs-1.c: Remove unnecessary declaration. * gcc.c-torture/execute/builtins/lib/main.c: Define link_error when not optimizing. From-SVN: r84044
Diffstat (limited to 'gcc/testsuite/gcc.c-torture')
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/abs-1.c1
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/abs-2-lib.c1
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/abs-2.c (renamed from gcc/testsuite/gcc.c-torture/execute/builtin-abs-1.c)89
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/abs-3-lib.c1
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/abs-3.c (renamed from gcc/testsuite/gcc.c-torture/execute/builtin-abs-2.c)89
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/complex-1-lib.c70
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/complex-1.c (renamed from gcc/testsuite/gcc.c-torture/execute/builtin-complex-1.c)115
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/fprintf-lib.c1
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/fprintf.c (renamed from gcc/testsuite/gcc.c-torture/execute/stdio-opt-3.c)18
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/fputs-lib.c17
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/fputs.c (renamed from gcc/testsuite/gcc.c-torture/execute/stdio-opt-1.c)21
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/lib/abs.c50
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/lib/fprintf.c18
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/lib/main.c12
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/lib/memset.c (renamed from gcc/testsuite/gcc.c-torture/execute/builtins/string-3-lib.c)0
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/lib/printf.c19
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/lib/sprintf.c20
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/lib/strcpy.c13
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/lib/strcspn.c20
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/lib/strncat.c26
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/lib/strncmp.c25
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/lib/strncpy.c19
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/lib/strpbrk.c19
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/lib/strspn.c23
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/lib/strstr.c27
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/memcmp-lib.c (renamed from gcc/testsuite/gcc.c-torture/execute/builtins/string-6-lib.c)0
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/memcmp.c (renamed from gcc/testsuite/gcc.c-torture/execute/string-opt-15.c)28
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/memmove-lib.c (renamed from gcc/testsuite/gcc.c-torture/execute/builtins/string-5-lib.c)0
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/memmove.c (renamed from gcc/testsuite/gcc.c-torture/execute/builtins/string-5.c)0
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/memops-asm-lib.c (renamed from gcc/testsuite/gcc.c-torture/execute/builtins/string-asm-2-lib.c)0
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/memops-asm.c (renamed from gcc/testsuite/gcc.c-torture/execute/builtins/string-asm-2.c)0
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/mempcpy-2-lib.c (renamed from gcc/testsuite/gcc.c-torture/execute/builtins/string-4-lib.c)1
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/mempcpy-2.c (renamed from gcc/testsuite/gcc.c-torture/execute/builtins/string-7.c)18
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/mempcpy-lib.c (renamed from gcc/testsuite/gcc.c-torture/execute/builtins/string-7-lib.c)1
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/mempcpy.c (renamed from gcc/testsuite/gcc.c-torture/execute/builtins/string-4.c)44
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/memset-lib.c1
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/memset.c (renamed from gcc/testsuite/gcc.c-torture/execute/builtins/string-3.c)0
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/printf-lib.c1
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/printf.c (renamed from gcc/testsuite/gcc.c-torture/execute/stdio-opt-2.c)17
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/sprintf-lib.c1
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/sprintf.c (renamed from gcc/testsuite/gcc.c-torture/execute/string-opt-16.c)18
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strcat-lib.c (renamed from gcc/testsuite/gcc.c-torture/execute/builtins/string-9-lib.c)0
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strcat.c (renamed from gcc/testsuite/gcc.c-torture/execute/builtins/string-9.c)0
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strchr-lib.c (renamed from gcc/testsuite/gcc.c-torture/execute/builtins/string-2-lib.c)0
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strchr.c (renamed from gcc/testsuite/gcc.c-torture/execute/builtins/string-2.c)0
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strcmp-lib.c1
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strcmp.c48
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strcpy-lib.c1
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strcpy.c (renamed from gcc/testsuite/gcc.c-torture/execute/string-opt-6.c)17
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strcspn-lib.c1
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strcspn.c (renamed from gcc/testsuite/gcc.c-torture/execute/string-opt-12.c)19
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/string-1-lib.c3
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/string-1.c87
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/string-6.c34
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strlen-2-lib.c (renamed from gcc/testsuite/gcc.c-torture/execute/builtins/string-8-lib.c)0
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strlen-2.c (renamed from gcc/testsuite/gcc.c-torture/execute/builtins/string-8.c)1
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strlen-lib.c1
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strlen.c64
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strncat-lib.c1
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strncat.c (renamed from gcc/testsuite/gcc.c-torture/execute/string-opt-10.c)17
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strncmp-2-lib.c1
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strncmp-2.c (renamed from gcc/testsuite/gcc.c-torture/execute/string-opt-8.c)72
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strncmp-lib.c1
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strncmp.c74
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strncpy-lib.c1
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strncpy.c (renamed from gcc/testsuite/gcc.c-torture/execute/string-opt-7.c)15
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strpbrk-lib.c1
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strpbrk.c (renamed from gcc/testsuite/gcc.c-torture/execute/string-opt-2.c)17
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strpcpy-2-lib.c1
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strpcpy-2.c45
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strpcpy-lib.c1
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strpcpy.c60
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strrchr-lib.c1
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strrchr.c49
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strspn-lib.c1
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strspn.c (renamed from gcc/testsuite/gcc.c-torture/execute/string-opt-11.c)17
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strstr-asm-lib.c (renamed from gcc/testsuite/gcc.c-torture/execute/builtins/string-asm-1-lib.c)0
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strstr-asm.c (renamed from gcc/testsuite/gcc.c-torture/execute/builtins/string-asm-1.c)0
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strstr-lib.c1
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/builtins/strstr.c (renamed from gcc/testsuite/gcc.c-torture/execute/string-opt-1.c)17
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/string-opt-13.c59
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/string-opt-14.c42
82 files changed, 855 insertions, 760 deletions
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/abs-1.c b/gcc/testsuite/gcc.c-torture/execute/builtins/abs-1.c
index 1584515..6ca246d 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtins/abs-1.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/abs-1.c
@@ -9,7 +9,6 @@ int abs_called = 0;
extern int abs (int);
extern long labs (long);
extern void abort (void);
-extern void exit (int);
void
main_test (void)
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/abs-2-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/abs-2-lib.c
new file mode 100644
index 0000000..494e539
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/abs-2-lib.c
@@ -0,0 +1 @@
+#include "lib/abs.c"
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtin-abs-1.c b/gcc/testsuite/gcc.c-torture/execute/builtins/abs-2.c
index 8a34353..025488d 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtin-abs-1.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/abs-2.c
@@ -21,12 +21,10 @@ extern long labs (long);
extern long long llabs (long long);
extern intmax_t imaxabs (intmax_t);
extern void abort (void);
-extern void exit (int);
+extern void link_error (void);
-extern void link_failure (void);
-
-int
-main (void)
+void
+main_test (void)
{
/* For each type, test both runtime and compile time (constant folding)
optimization. */
@@ -39,122 +37,81 @@ main (void)
if (abs (i0) != 0)
abort ();
if (abs (0) != 0)
- link_failure ();
+ link_error ();
if (abs (i1) != 1)
abort ();
if (abs (1) != 1)
- link_failure ();
+ link_error ();
if (abs (im1) != 1)
abort ();
if (abs (-1) != 1)
- link_failure ();
+ link_error ();
if (abs (imin) != INT_MAX)
abort ();
if (abs (-INT_MAX) != INT_MAX)
- link_failure ();
+ link_error ();
if (abs (imax) != INT_MAX)
abort ();
if (abs (INT_MAX) != INT_MAX)
- link_failure ();
+ link_error ();
if (labs (l0) != 0L)
abort ();
if (labs (0L) != 0L)
- link_failure ();
+ link_error ();
if (labs (l1) != 1L)
abort ();
if (labs (1L) != 1L)
- link_failure ();
+ link_error ();
if (labs (lm1) != 1L)
abort ();
if (labs (-1L) != 1L)
- link_failure ();
+ link_error ();
if (labs (lmin) != LONG_MAX)
abort ();
if (labs (-LONG_MAX) != LONG_MAX)
- link_failure ();
+ link_error ();
if (labs (lmax) != LONG_MAX)
abort ();
if (labs (LONG_MAX) != LONG_MAX)
- link_failure ();
+ link_error ();
if (llabs (ll0) != 0LL)
abort ();
if (llabs (0LL) != 0LL)
- link_failure ();
+ link_error ();
if (llabs (ll1) != 1LL)
abort ();
if (llabs (1LL) != 1LL)
- link_failure ();
+ link_error ();
if (llabs (llm1) != 1LL)
abort ();
if (llabs (-1LL) != 1LL)
- link_failure ();
+ link_error ();
if (llabs (llmin) != __LONG_LONG_MAX__)
abort ();
if (llabs (-__LONG_LONG_MAX__) != __LONG_LONG_MAX__)
- link_failure ();
+ link_error ();
if (llabs (llmax) != __LONG_LONG_MAX__)
abort ();
if (llabs (__LONG_LONG_MAX__) != __LONG_LONG_MAX__)
- link_failure ();
+ link_error ();
if (imaxabs (imax0) != 0)
abort ();
if (imaxabs (0) != 0)
- link_failure ();
+ link_error ();
if (imaxabs (imax1) != 1)
abort ();
if (imaxabs (1) != 1)
- link_failure ();
+ link_error ();
if (imaxabs (imaxm1) != 1)
abort ();
if (imaxabs (-1) != 1)
- link_failure ();
+ link_error ();
if (imaxabs (imaxmin) != INTMAX_MAX)
abort ();
if (imaxabs (-INTMAX_MAX) != INTMAX_MAX)
- link_failure ();
+ link_error ();
if (imaxabs (imaxmax) != INTMAX_MAX)
abort ();
if (imaxabs (INTMAX_MAX) != INTMAX_MAX)
- link_failure ();
- exit (0);
-}
-
-/* All the above cases should have been optimized to something else,
- even if not optimizing (unless -fno-builtin was specified). So any
- remaining calls to the original functions should abort. */
-
-static int
-abs (int x)
-{
- abort ();
+ link_error ();
}
-
-static long
-labs (long x)
-{
- abort ();
-}
-
-static long long
-llabs (long long x)
-{
- abort ();
-}
-
-static intmax_t
-imaxabs (intmax_t x)
-{
- abort ();
-}
-
-/* When optimizing, all the constant cases should have been
- constant folded, so no calls to link_failure should remain. In any case,
- link_failure should not be called. */
-
-#ifndef __OPTIMIZE__
-void
-link_failure (void)
-{
- abort ();
-}
-#endif
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/abs-3-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/abs-3-lib.c
new file mode 100644
index 0000000..494e539
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/abs-3-lib.c
@@ -0,0 +1 @@
+#include "lib/abs.c"
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtin-abs-2.c b/gcc/testsuite/gcc.c-torture/execute/builtins/abs-3.c
index b4e1879..8300a48 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtin-abs-2.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/abs-3.c
@@ -17,12 +17,10 @@ typedef long long intmax_t;
#endif
extern void abort (void);
-extern void exit (int);
+extern void link_error (void);
-extern void link_failure (void);
-
-int
-main (void)
+void
+main_test (void)
{
/* For each type, test both runtime and compile time (constant folding)
optimization. */
@@ -35,122 +33,81 @@ main (void)
if (__builtin_abs (i0) != 0)
abort ();
if (__builtin_abs (0) != 0)
- link_failure ();
+ link_error ();
if (__builtin_abs (i1) != 1)
abort ();
if (__builtin_abs (1) != 1)
- link_failure ();
+ link_error ();
if (__builtin_abs (im1) != 1)
abort ();
if (__builtin_abs (-1) != 1)
- link_failure ();
+ link_error ();
if (__builtin_abs (imin) != INT_MAX)
abort ();
if (__builtin_abs (-INT_MAX) != INT_MAX)
- link_failure ();
+ link_error ();
if (__builtin_abs (imax) != INT_MAX)
abort ();
if (__builtin_abs (INT_MAX) != INT_MAX)
- link_failure ();
+ link_error ();
if (__builtin_labs (l0) != 0L)
abort ();
if (__builtin_labs (0L) != 0L)
- link_failure ();
+ link_error ();
if (__builtin_labs (l1) != 1L)
abort ();
if (__builtin_labs (1L) != 1L)
- link_failure ();
+ link_error ();
if (__builtin_labs (lm1) != 1L)
abort ();
if (__builtin_labs (-1L) != 1L)
- link_failure ();
+ link_error ();
if (__builtin_labs (lmin) != LONG_MAX)
abort ();
if (__builtin_labs (-LONG_MAX) != LONG_MAX)
- link_failure ();
+ link_error ();
if (__builtin_labs (lmax) != LONG_MAX)
abort ();
if (__builtin_labs (LONG_MAX) != LONG_MAX)
- link_failure ();
+ link_error ();
if (__builtin_llabs (ll0) != 0LL)
abort ();
if (__builtin_llabs (0LL) != 0LL)
- link_failure ();
+ link_error ();
if (__builtin_llabs (ll1) != 1LL)
abort ();
if (__builtin_llabs (1LL) != 1LL)
- link_failure ();
+ link_error ();
if (__builtin_llabs (llm1) != 1LL)
abort ();
if (__builtin_llabs (-1LL) != 1LL)
- link_failure ();
+ link_error ();
if (__builtin_llabs (llmin) != __LONG_LONG_MAX__)
abort ();
if (__builtin_llabs (-__LONG_LONG_MAX__) != __LONG_LONG_MAX__)
- link_failure ();
+ link_error ();
if (__builtin_llabs (llmax) != __LONG_LONG_MAX__)
abort ();
if (__builtin_llabs (__LONG_LONG_MAX__) != __LONG_LONG_MAX__)
- link_failure ();
+ link_error ();
if (__builtin_imaxabs (imax0) != 0)
abort ();
if (__builtin_imaxabs (0) != 0)
- link_failure ();
+ link_error ();
if (__builtin_imaxabs (imax1) != 1)
abort ();
if (__builtin_imaxabs (1) != 1)
- link_failure ();
+ link_error ();
if (__builtin_imaxabs (imaxm1) != 1)
abort ();
if (__builtin_imaxabs (-1) != 1)
- link_failure ();
+ link_error ();
if (__builtin_imaxabs (imaxmin) != INTMAX_MAX)
abort ();
if (__builtin_imaxabs (-INTMAX_MAX) != INTMAX_MAX)
- link_failure ();
+ link_error ();
if (__builtin_imaxabs (imaxmax) != INTMAX_MAX)
abort ();
if (__builtin_imaxabs (INTMAX_MAX) != INTMAX_MAX)
- link_failure ();
- exit (0);
-}
-
-/* All the above cases should have been optimized to something else,
- not converted to function calls. So any calls to the non-__builtin
- functions should abort. */
-
-static int
-abs (int x)
-{
- abort ();
+ link_error ();
}
-
-static long
-labs (long x)
-{
- abort ();
-}
-
-static long long
-llabs (long long x)
-{
- abort ();
-}
-
-static intmax_t
-imaxabs (intmax_t x)
-{
- abort ();
-}
-
-/* When optimizing, all the constant cases should have been
- constant folded, so no calls to link_failure should remain. In any case,
- link_failure should not be called. */
-
-#ifndef __OPTIMIZE__
-void
-link_failure (void)
-{
- abort ();
-}
-#endif
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/complex-1-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/complex-1-lib.c
new file mode 100644
index 0000000..22d7db1
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/complex-1-lib.c
@@ -0,0 +1,70 @@
+extern int inside_main;
+extern void abort (void);
+#ifdef __OPTIMIZE__
+#define ABORT_INSIDE_MAIN do { if (inside_main) abort (); } while (0)
+#else
+#define ABORT_INSIDE_MAIN do { } while (0)
+#endif
+
+static float _Complex
+conjf (float _Complex z)
+{
+ ABORT_INSIDE_MAIN;
+ return ~z;
+}
+
+static double _Complex
+conj (double _Complex z)
+{
+ ABORT_INSIDE_MAIN;
+ return ~z;
+}
+
+static long double _Complex
+conjl (long double _Complex z)
+{
+ ABORT_INSIDE_MAIN;
+ return ~z;
+}
+
+static float
+crealf (float _Complex z)
+{
+ ABORT_INSIDE_MAIN;
+ return __real__ z;
+}
+
+static double
+creal (double _Complex z)
+{
+ ABORT_INSIDE_MAIN;
+ return __real__ z;
+}
+
+static long double
+creall (long double _Complex z)
+{
+ ABORT_INSIDE_MAIN;
+ return __real__ z;
+}
+
+static float
+cimagf (float _Complex z)
+{
+ ABORT_INSIDE_MAIN;
+ return __imag__ z;
+}
+
+static double
+cimag (double _Complex z)
+{
+ ABORT_INSIDE_MAIN;
+ return __imag__ z;
+}
+
+static long double
+cimagl (long double _Complex z)
+{
+ ABORT_INSIDE_MAIN;
+ return __imag__ z;
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtin-complex-1.c b/gcc/testsuite/gcc.c-torture/execute/builtins/complex-1.c
index 46ab7c5..362a0e4 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtin-complex-1.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/complex-1.c
@@ -14,12 +14,10 @@ extern double cimag (double _Complex);
extern long double cimagl (long double _Complex);
extern void abort (void);
-extern void exit (int);
+extern void link_error (void);
-extern void link_failure (void);
-
-int
-main (void)
+void
+main_test (void)
{
/* For each type, test both runtime and compile time (constant folding)
optimization. */
@@ -32,144 +30,73 @@ main (void)
if (__builtin_conjf (fc) != 1.0F - 2.0iF)
abort ();
if (conjf (1.0F + 2.0iF) != 1.0F - 2.0iF)
- link_failure ();
+ link_error ();
if (__builtin_conjf (1.0F + 2.0iF) != 1.0F - 2.0iF)
- link_failure ();
+ link_error ();
if (crealf (fc) != 1.0F)
abort ();
if (__builtin_crealf (fc) != 1.0F)
abort ();
if (crealf (1.0F + 2.0iF) != 1.0F)
- link_failure ();
+ link_error ();
if (__builtin_crealf (1.0F + 2.0iF) != 1.0F)
- link_failure ();
+ link_error ();
if (cimagf (fc) != 2.0F)
abort ();
if (__builtin_cimagf (fc) != 2.0F)
abort ();
if (cimagf (1.0F + 2.0iF) != 2.0F)
- link_failure ();
+ link_error ();
if (__builtin_cimagf (1.0F + 2.0iF) != 2.0F)
- link_failure ();
+ link_error ();
/* Test doubles. */
if (conj (dc) != 1.0 - 2.0i)
abort ();
if (__builtin_conj (dc) != 1.0 - 2.0i)
abort ();
if (conj (1.0 + 2.0i) != 1.0 - 2.0i)
- link_failure ();
+ link_error ();
if (__builtin_conj (1.0 + 2.0i) != 1.0 - 2.0i)
- link_failure ();
+ link_error ();
if (creal (dc) != 1.0)
abort ();
if (__builtin_creal (dc) != 1.0)
abort ();
if (creal (1.0 + 2.0i) != 1.0)
- link_failure ();
+ link_error ();
if (__builtin_creal (1.0 + 2.0i) != 1.0)
- link_failure ();
+ link_error ();
if (cimag (dc) != 2.0)
abort ();
if (__builtin_cimag (dc) != 2.0)
abort ();
if (cimag (1.0 + 2.0i) != 2.0)
- link_failure ();
+ link_error ();
if (__builtin_cimag (1.0 + 2.0i) != 2.0)
- link_failure ();
+ link_error ();
/* Test long doubles. */
if (conjl (ldc) != 1.0L - 2.0iL)
abort ();
if (__builtin_conjl (ldc) != 1.0L - 2.0iL)
abort ();
if (conjl (1.0L + 2.0iL) != 1.0L - 2.0iL)
- link_failure ();
+ link_error ();
if (__builtin_conjl (1.0L + 2.0iL) != 1.0L - 2.0iL)
- link_failure ();
+ link_error ();
if (creall (ldc) != 1.0L)
abort ();
if (__builtin_creall (ldc) != 1.0L)
abort ();
if (creall (1.0L + 2.0iL) != 1.0L)
- link_failure ();
+ link_error ();
if (__builtin_creall (1.0L + 2.0iL) != 1.0L)
- link_failure ();
+ link_error ();
if (cimagl (ldc) != 2.0L)
abort ();
if (__builtin_cimagl (ldc) != 2.0L)
abort ();
if (cimagl (1.0L + 2.0iL) != 2.0L)
- link_failure ();
+ link_error ();
if (__builtin_cimagl (1.0L + 2.0iL) != 2.0L)
- link_failure ();
- exit (0);
-}
-
-/* All the above cases should have been optimized to something else,
- even if not optimizing (unless -fno-builtin was specified). So any
- remaining calls to the original functions should abort. */
-
-static float _Complex
-conjf (float _Complex z)
-{
- abort ();
-}
-
-static double _Complex
-conj (double _Complex z)
-{
- abort ();
-}
-
-static long double _Complex
-conjl (long double _Complex z)
-{
- abort ();
-}
-
-static float
-crealf (float _Complex z)
-{
- abort ();
-}
-
-static double
-creal (double _Complex z)
-{
- abort ();
-}
-
-static long double
-creall (long double _Complex z)
-{
- abort ();
-}
-
-static float
-cimagf (float _Complex z)
-{
- abort ();
-}
-
-static double
-cimag (double _Complex z)
-{
- abort ();
-}
-
-static long double
-cimagl (long double _Complex z)
-{
- abort ();
-}
-
-/* When optimizing, all the constant cases should have been
- constant folded, so no calls to link_failure should remain. In any case,
- link_failure should not be called. */
-
-#ifndef __OPTIMIZE__
-void
-link_failure (void)
-{
- abort ();
+ link_error ();
}
-#endif
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/fprintf-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/fprintf-lib.c
new file mode 100644
index 0000000..b6a1e91
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/fprintf-lib.c
@@ -0,0 +1 @@
+#include "lib/fprintf.c"
diff --git a/gcc/testsuite/gcc.c-torture/execute/stdio-opt-3.c b/gcc/testsuite/gcc.c-torture/execute/builtins/fprintf.c
index afc76a2..6b6e71b 100644
--- a/gcc/testsuite/gcc.c-torture/execute/stdio-opt-3.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/fprintf.c
@@ -6,10 +6,10 @@
Written by Kaveh R. Ghazi, 1/7/2001. */
#include <stdio.h>
-extern int fprintf (FILE *, const char *, ...);
extern void abort(void);
-int main()
+void
+main_test (void)
{
FILE *s_array[] = {stdout, NULL}, **s_ptr = s_array;
const char *const s1 = "hello world";
@@ -49,18 +49,4 @@ int main()
/* Test at least one instance of the __builtin_ style. We do this
to ensure that it works and that the prototype is correct. */
__builtin_fprintf (*s_ptr, "%s", "hello world\n");
-
- return 0;
-}
-
-#ifdef __OPTIMIZE__
-/* When optimizing, all the above cases should be transformed into
- something else. So any remaining calls to the original function
- should abort. */
-__attribute__ ((noinline))
-static int
-fprintf (FILE *stream, const char *string, ...)
-{
- abort();
}
-#endif
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/fputs-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/fputs-lib.c
new file mode 100644
index 0000000..48a9553
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/fputs-lib.c
@@ -0,0 +1,17 @@
+#include <stdio.h>
+#include <stddef.h>
+extern int inside_main;
+extern size_t strlen(const char *);
+int
+fputs(const char *string, FILE *stream)
+{
+ size_t n = strlen(string);
+ size_t r;
+#if defined __OPTIMIZE__ && !defined __OPTIMIZE_SIZE__
+ if (inside_main)
+ abort();
+#endif
+ r = fwrite (string, 1, n, stream);
+ return n > r ? EOF : 0;
+}
+
diff --git a/gcc/testsuite/gcc.c-torture/execute/stdio-opt-1.c b/gcc/testsuite/gcc.c-torture/execute/builtins/fputs.c
index 8cfb4eb..9274d5b 100644
--- a/gcc/testsuite/gcc.c-torture/execute/stdio-opt-1.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/fputs.c
@@ -7,14 +7,11 @@
#include <stdio.h>
extern void abort(void);
-/* Declare this without args because that's what gcc does internally.
- We want to make sure it works without a helpful prototype from us.
- If stdio.h provides one, that is okay. */
-extern int fputs();
int i;
-int main()
+void
+main_test(void)
{
FILE *s_array[] = {stdout, NULL}, **s_ptr = s_array;
const char *const s1 = "hello world";
@@ -61,18 +58,4 @@ int main()
fputs (--i ? "\n" : "\n", *--s_ptr);
if (s_ptr != s_array || i != 0)
abort();
-
- return 0;
-}
-
-#if defined (__OPTIMIZE__) && ! defined (__OPTIMIZE_SIZE__)
-/* When optimizing, all the above cases should be transformed into
- something else. So any remaining calls to the original function
- should abort. */
-__attribute__ ((noinline))
-static int
-fputs(const char *string, FILE *stream)
-{
- abort();
}
-#endif
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/abs.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/abs.c
new file mode 100644
index 0000000..99ca10d
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/abs.c
@@ -0,0 +1,50 @@
+extern int inside_main;
+extern void abort (void);
+#ifdef __OPTIMIZE__
+#define ABORT_INSIDE_MAIN do { if (inside_main) abort (); } while (0)
+#else
+#define ABORT_INSIDE_MAIN do { } while (0)
+#endif
+
+/* These next definitions are kludges. When GCC has a <stdint.h> it
+ should be used.
+*/
+#include <limits.h>
+#if INT_MAX == __LONG_LONG_MAX__
+typedef int intmax_t;
+#define INTMAX_MAX INT_MAX
+#elif LONG_MAX == __LONG_LONG_MAX__
+typedef long intmax_t;
+#define INTMAX_MAX LONG_MAX
+#else
+typedef long long intmax_t;
+#define INTMAX_MAX __LONG_LONG_MAX__
+#endif
+
+int
+abs (int x)
+{
+ ABORT_INSIDE_MAIN;
+ return x < 0 ? -x : x;
+}
+
+long
+labs (long x)
+{
+ ABORT_INSIDE_MAIN;
+ return x < 0 ? -x : x;
+}
+
+long long
+llabs (long long x)
+{
+ ABORT_INSIDE_MAIN;
+ return x < 0 ? -x : x;
+}
+
+intmax_t
+imaxabs (intmax_t x)
+{
+ ABORT_INSIDE_MAIN;
+ return x < 0 ? -x : x;
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/fprintf.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/fprintf.c
new file mode 100644
index 0000000..80c240c
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/fprintf.c
@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include <stdarg.h>
+extern int inside_main;
+
+int
+fprintf (FILE *fp, const char *string, ...)
+{
+ va_list ap;
+ int r;
+#ifdef __OPTIMIZE__
+ if (inside_main)
+ abort();
+#endif
+ va_start (ap, string);
+ r = vfprintf (fp, string, ap);
+ va_end (ap);
+ return r;
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/main.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/main.c
index cfd79ba..6f3c317 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/main.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/main.c
@@ -9,3 +9,15 @@ main ()
inside_main = 0;
return 0;
}
+
+/* When optimizing, all the constant cases should have been
+ constant folded, so no calls to link_error should remain.
+ In any case, link_error should not be called. */
+
+#ifndef __OPTIMIZE__
+void
+link_error (void)
+{
+ abort ();
+}
+#endif
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-3-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/memset.c
index d5326ff..d5326ff 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-3-lib.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/memset.c
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/printf.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/printf.c
new file mode 100644
index 0000000..be2a63b
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/printf.c
@@ -0,0 +1,19 @@
+#include <stdio.h>
+#include <stdarg.h>
+extern int inside_main;
+
+int
+printf (const char *string, ...)
+{
+ va_list ap;
+ int r;
+#ifdef __OPTIMIZE__
+ if (inside_main)
+ abort();
+#endif
+ va_start (ap, string);
+ r = vprintf (string, ap);
+ va_end (ap);
+ return r;
+}
+
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/sprintf.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/sprintf.c
new file mode 100644
index 0000000..0c0cd5b
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/sprintf.c
@@ -0,0 +1,20 @@
+#include <stdio.h>
+#include <stdarg.h>
+extern int inside_main;
+
+int
+sprintf (char *buf, const char *fmt, ...)
+{
+ va_list ap;
+ int r;
+#ifdef __OPTIMIZE__
+ if (inside_main)
+ abort ();
+#endif
+ va_start (ap, fmt);
+ r = vsprintf (buf, fmt, ap);
+ va_end (ap);
+ return r;
+}
+
+
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strcpy.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strcpy.c
new file mode 100644
index 0000000..127b577
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strcpy.c
@@ -0,0 +1,13 @@
+extern int inside_main;
+
+char *
+strcpy (char *d, const char *s)
+{
+ char *r = d;
+#ifdef __OPTIMIZE__
+ if (inside_main)
+ abort ();
+#endif
+ while ((*d++ = *s++));
+ return r;
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strcspn.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strcspn.c
new file mode 100644
index 0000000..767c89a
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strcspn.c
@@ -0,0 +1,20 @@
+extern int inside_main;
+
+__SIZE_TYPE__
+strcspn (const char *s1, const char *s2)
+{
+ const char *p, *q;
+
+#ifdef __OPTIMIZE__
+ if (inside_main)
+ abort();
+#endif
+
+ for (p = s1; *p; p++)
+ for (q = s2; *q; q++)
+ if (*p == *q)
+ goto found;
+
+ found:
+ return p - s1;
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strncat.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strncat.c
new file mode 100644
index 0000000..59d3cc0
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strncat.c
@@ -0,0 +1,26 @@
+extern int inside_main;
+
+typedef __SIZE_TYPE__ size_t;
+
+char *
+strncat (char *s1, const char *s2, size_t n)
+{
+ char *dest = s1;
+ char c;
+#ifdef __OPTIMIZE__
+ if (inside_main)
+ abort();
+#endif
+ while (*s1) s1++;
+ while (n > 0)
+ {
+ c = *s2++;
+ *s1++ = c;
+ if (c == 0)
+ return dest;
+ n--;
+ }
+ if (c != '\0')
+ *s1 = '\0';
+ return dest;
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strncmp.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strncmp.c
new file mode 100644
index 0000000..c0b8906
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strncmp.c
@@ -0,0 +1,25 @@
+extern int inside_main;
+
+typedef __SIZE_TYPE__ size_t;
+
+int
+strncmp(const char *s1, const char *s2, size_t n)
+{
+ const unsigned char *u1 = (const unsigned char *)s1;
+ const unsigned char *u2 = (const unsigned char *)s2;
+ unsigned char c1, c2;
+
+#ifdef __OPTIMIZE__
+ if (inside_main)
+ abort();
+#endif
+
+ while (n > 0)
+ {
+ c1 = *u1++, c2 = *u2++;
+ if (c1 == '\0' || c1 != c2)
+ return c1 - c2;
+ n--;
+ }
+ return c1 - c2;
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strncpy.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strncpy.c
new file mode 100644
index 0000000..a96f7cb
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strncpy.c
@@ -0,0 +1,19 @@
+extern int inside_main;
+
+typedef __SIZE_TYPE__ size_t;
+
+char *
+strncpy(char *s1, const char *s2, size_t n)
+{
+ char *dest = s1;
+#ifdef __OPTIMIZE__
+ if (inside_main)
+ abort();
+#endif
+ for (; *s2 && n; n--)
+ *s1++ = *s2++;
+ while (n--)
+ *s1++ = 0;
+ return dest;
+}
+
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strpbrk.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strpbrk.c
new file mode 100644
index 0000000..1eb90ad
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strpbrk.c
@@ -0,0 +1,19 @@
+extern int inside_main;
+
+char *
+strpbrk(const char *s1, const char *s2)
+{
+ char *p;
+#ifdef __OPTIMIZE__
+ if (inside_main)
+ abort ();
+#endif
+ while (*s1)
+ {
+ for (p = s2; *p; p++)
+ if (*s1 == *p)
+ return s1;
+ s1++;
+ }
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strspn.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strspn.c
new file mode 100644
index 0000000..29477cc
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strspn.c
@@ -0,0 +1,23 @@
+extern int inside_main;
+
+__SIZE_TYPE__
+strcspn (const char *s1, const char *s2)
+{
+ const char *p, *q;
+
+#ifdef __OPTIMIZE__
+ if (inside_main)
+ abort();
+#endif
+
+ for (p = s1; *p; p++)
+ {
+ for (q = s2; *q; q++)
+ if (*p == *q)
+ goto proceed;
+ break;
+
+ proceed:;
+ }
+ return p - s1;
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strstr.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strstr.c
new file mode 100644
index 0000000..fa43c93
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strstr.c
@@ -0,0 +1,27 @@
+extern int inside_main;
+
+char *
+strstr(const char *s1, const char *s2)
+{
+ const char *p, *q;
+
+#ifdef __OPTIMIZE__
+ if (inside_main)
+ abort ();
+#endif
+
+ /* deliberately dumb algorithm */
+ for (; *s1; s1++)
+ {
+ p = s1, q = s2;
+ while (*q && *p)
+ {
+ if (*q != *p)
+ break;
+ p++, q++;
+ }
+ if (*p == *q && *p == 0)
+ return (char *)s1;
+ }
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-6-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/memcmp-lib.c
index 029a92e..029a92e 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-6-lib.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/memcmp-lib.c
diff --git a/gcc/testsuite/gcc.c-torture/execute/string-opt-15.c b/gcc/testsuite/gcc.c-torture/execute/builtins/memcmp.c
index e2395d4..5489048 100644
--- a/gcc/testsuite/gcc.c-torture/execute/string-opt-15.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/memcmp.c
@@ -4,15 +4,17 @@
On architectures with a cmpstrsi instruction, this test doesn't determine
which optimization is being performed, but it does check for correctness.
- Written by Roger Sayle, 12/02/2001. */
+ Written by Roger Sayle, 12/02/2001.
+ Additional tests by Roger Sayle after PR 3508, 12/26/2001. */
extern void abort (void);
typedef __SIZE_TYPE__ size_t;
extern int memcmp (const void *, const void *, size_t);
extern char *strcpy (char *, const char *);
+extern void link_error (void);
-int
-main ()
+void
+main_test (void)
{
char str[8];
@@ -30,18 +32,10 @@ main ()
if ( memcmp (str+2, str, 1) <= 0 )
abort ();
- return 0;
+ if (memcmp ("abcd", "efgh", 4) >= 0)
+ link_error ();
+ if (memcmp ("abcd", "abcd", 4) != 0)
+ link_error ();
+ if (memcmp ("efgh", "abcd", 4) <= 0)
+ link_error ();
}
-
-#ifdef __OPTIMIZE__
-/* When optimizing, all the above cases should be transformed into
- something else. So any remaining calls to the original function
- should abort. */
-__attribute__ ((noinline))
-static int
-memcmp (const void *p1, const void *p2, size_t len)
-{
- abort ();
-}
-#endif
-
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-5-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/memmove-lib.c
index 5be3df5..5be3df5 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-5-lib.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/memmove-lib.c
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-5.c b/gcc/testsuite/gcc.c-torture/execute/builtins/memmove.c
index 4a18fc6..4a18fc6 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-5.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/memmove.c
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-asm-2-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/memops-asm-lib.c
index 16369a2..16369a2 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-asm-2-lib.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/memops-asm-lib.c
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-asm-2.c b/gcc/testsuite/gcc.c-torture/execute/builtins/memops-asm.c
index e793778..e793778 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-asm-2.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/memops-asm.c
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-4-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/mempcpy-2-lib.c
index 3b69c3b..cf3178c 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-4-lib.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/mempcpy-2-lib.c
@@ -1,2 +1 @@
-#include "lib/stpcpy.c"
#include "lib/mempcpy.c"
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-7.c b/gcc/testsuite/gcc.c-torture/execute/builtins/mempcpy-2.c
index 5eb1ac4..dcaf07b 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-7.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/mempcpy-2.c
@@ -8,7 +8,6 @@ extern void abort (void);
typedef __SIZE_TYPE__ size_t;
extern void *mempcpy (void *, const void *, size_t);
extern int memcmp (const void *, const void *, size_t);
-extern char *stpcpy (char *, const char *);
extern int inside_main;
long buf1[64];
@@ -16,7 +15,7 @@ char *buf2 = (char *) (buf1 + 32);
long buf5[20];
char buf7[20];
-int
+void
__attribute__((noinline))
test (long *buf3, char *buf4, char *buf6, int n)
{
@@ -141,21 +140,6 @@ test (long *buf3, char *buf4, char *buf6, int n)
if (mempcpy (buf4 + 14, buf6, n + 2) != buf2 + 16
|| memcmp (buf2, "aBcdRSTUVWkSmnrsq\0", 19))
abort ();
-
- /* Now stpcpy tests. */
- if (stpcpy ((char *) buf3, "abcdefghijklmnop") != (char *) buf1 + 16
- || memcmp (buf1, "abcdefghijklmnop", 17))
- abort ();
-
- if (__builtin_stpcpy ((char *) buf3, "ABCDEFG") != (char *) buf1 + 7
- || memcmp (buf1, "ABCDEFG\0ijklmnop", 17))
- abort ();
-
- if (stpcpy ((char *) buf3 + i++, "x") != (char *) buf1 + 5
- || memcmp (buf1, "ABCDx\0G\0ijklmnop", 17))
- abort ();
-
- return 0;
}
void
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-7-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/mempcpy-lib.c
index 3b69c3b..cf3178c 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-7-lib.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/mempcpy-lib.c
@@ -1,2 +1 @@
-#include "lib/stpcpy.c"
#include "lib/mempcpy.c"
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-4.c b/gcc/testsuite/gcc.c-torture/execute/builtins/mempcpy.c
index 51819b1..d82e223 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-4.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/mempcpy.c
@@ -1,12 +1,10 @@
/* Copyright (C) 2003 Free Software Foundation.
- Ensure builtin mempcpy and stpcpy perform correctly.
+ Ensure builtin mempcpy performs 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);
@@ -32,55 +30,39 @@ main_test (void)
inside_main = 0;
#endif
- 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))
+ if (mempcpy (p + 16, "VWX" + 1, 2) != p + 16 + 2
+ || memcmp (p + 16, "WX\0\0", 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))
+ if (mempcpy (p + 3, "FGHI", 4) != p + 3 + 4 || memcmp (p, "A\0CFGHI", 8))
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 ();
-
memcpy (p + 25, "QRSTU", 6);
- if (mempcpy (p + 25 + 1, s1, 3) != (p + 25 + 1 + 3) || memcmp (p + 25, "Q123U", 6))
+ if (mempcpy (p + 25 + 1, s1, 3) != (p + 25 + 1 + 3)
+ || 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))
+ 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. This should be optimized always, so set inside_main
- again. */
+ /* If the result of mempcpy is ignored, gcc should use memcpy.
+ This should be optimized always, so set inside_main again. */
inside_main = 1;
- stpcpy (p + 3, s2);
- if (memcmp (p, "ABCdefg", 8))
- abort ();
mempcpy (p + 5, s3, 1);
- if (memcmp (p, "ABCdeFg", 8))
+ if (memcmp (p, "ABCDEFg", 8))
abort ();
- mempcpy (p + 6, s3 + 1, l1);
- if (memcmp (p, "ABCdeFG", 8))
+ mempcpy (p + 6, s1 + 1, l1);
+ if (memcmp (p, "ABCDEF2", 8))
abort ();
}
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/memset-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/memset-lib.c
new file mode 100644
index 0000000..2eeff38
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/memset-lib.c
@@ -0,0 +1 @@
+#include "lib/memset.c"
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-3.c b/gcc/testsuite/gcc.c-torture/execute/builtins/memset.c
index cf7c1e3..cf7c1e3 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-3.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/memset.c
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/printf-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/printf-lib.c
new file mode 100644
index 0000000..45ed7ec
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/printf-lib.c
@@ -0,0 +1 @@
+#include "lib/printf.c"
diff --git a/gcc/testsuite/gcc.c-torture/execute/stdio-opt-2.c b/gcc/testsuite/gcc.c-torture/execute/builtins/printf.c
index 833017e..0d01e54 100644
--- a/gcc/testsuite/gcc.c-torture/execute/stdio-opt-2.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/printf.c
@@ -8,7 +8,8 @@
extern int printf (const char *, ...);
extern void abort(void);
-int main()
+void
+main_test (void)
{
const char *const s1 = "hello world";
const char *const s2[] = { s1, 0 }, *const*s3;
@@ -37,18 +38,4 @@ int main()
prototypes are set correctly too. */
__builtin_putchar ('\n');
__builtin_puts ("hello");
-
- return 0;
-}
-
-#ifdef __OPTIMIZE__
-/* When optimizing, all the above cases should be transformed into
- something else. So any remaining calls to the original function
- should abort. */
-__attribute__ ((noinline))
-static int
-printf (const char *string, ...)
-{
- abort();
}
-#endif
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/sprintf-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/sprintf-lib.c
new file mode 100644
index 0000000..3a4fe34
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/sprintf-lib.c
@@ -0,0 +1 @@
+#include "lib/sprintf.c"
diff --git a/gcc/testsuite/gcc.c-torture/execute/string-opt-16.c b/gcc/testsuite/gcc.c-torture/execute/builtins/sprintf.c
index 8556b8f..b459264 100644
--- a/gcc/testsuite/gcc.c-torture/execute/string-opt-16.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/sprintf.c
@@ -39,7 +39,8 @@ void test5(char *ptr)
}
-int main()
+void
+main_test (void)
{
memset (buffer, 'A', 32);
test1 ();
@@ -67,19 +68,4 @@ int main()
test5 ("barf");
if (memcmp(buffer, "barf", 5) || buffer[5] != 'A')
abort ();
-
- return 0;
}
-
-#ifdef __OPTIMIZE__
-/* When optimizing, all the above cases should be transformed into
- something else. So any remaining calls to the original function
- should abort. */
-__attribute__ ((noinline))
-static int
-sprintf (char *buf, const char *fmt, ...)
-{
- abort ();
-}
-#endif
-
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-9-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strcat-lib.c
index 0a0bbb8..0a0bbb8 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-9-lib.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strcat-lib.c
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-9.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strcat.c
index ba70c39..ba70c39 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-9.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strcat.c
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-2-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strchr-lib.c
index 9049fb9..9049fb9 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-2-lib.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strchr-lib.c
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-2.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strchr.c
index 08e87c6..08e87c6 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-2.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strchr.c
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strcmp-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strcmp-lib.c
new file mode 100644
index 0000000..99c4214
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strcmp-lib.c
@@ -0,0 +1 @@
+#include "lib/strcmp.c"
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strcmp.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strcmp.c
new file mode 100644
index 0000000..08a7658
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strcmp.c
@@ -0,0 +1,48 @@
+/* Copyright (C) 2000, 2003, 2004 Free Software Foundation.
+
+ Ensure all expected transformations of builtin strcmp
+ occur and perform correctly.
+
+ Written by Jakub Jelinek, 11/7/2000. */
+
+extern void abort (void);
+extern int strcmp (const char *, const char *);
+
+int x = 7;
+char *bar = "hi world";
+
+void
+main_test (void)
+{
+ const char *const foo = "hello world";
+
+ 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 ();
+
+ /* 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_strcmp (foo, "hello") <= 0)
+ abort ();
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strcpy-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strcpy-lib.c
new file mode 100644
index 0000000..b10dfcb
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strcpy-lib.c
@@ -0,0 +1 @@
+#include "lib/strcpy.c"
diff --git a/gcc/testsuite/gcc.c-torture/execute/string-opt-6.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strcpy.c
index c684dbd..0ca62b3 100644
--- a/gcc/testsuite/gcc.c-torture/execute/string-opt-6.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strcpy.c
@@ -12,7 +12,8 @@ extern int memcmp (const void *, const void *, size_t);
char p[32] = "";
-int main()
+void
+main_test (void)
{
if (strcpy (p, "abcde") != p || memcmp (p, "abcde", 6))
abort ();
@@ -37,18 +38,4 @@ int main()
abort ();
if (__builtin_memcpy (p, "ABCDE", 6) != p || memcmp (p, "ABCDE", 6))
abort ();
-
- return 0;
-}
-
-#ifdef __OPTIMIZE__
-/* When optimizing, all the above cases should be transformed into
- something else. So any remaining calls to the original function
- should abort. */
-__attribute__ ((noinline))
-static char *
-strcpy (char *d, const char *s)
-{
- abort ();
}
-#endif
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strcspn-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strcspn-lib.c
new file mode 100644
index 0000000..8b1cfea
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strcspn-lib.c
@@ -0,0 +1 @@
+#include "lib/strcspn.c"
diff --git a/gcc/testsuite/gcc.c-torture/execute/string-opt-12.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strcspn.c
index 1d20f1e..be39254 100644
--- a/gcc/testsuite/gcc.c-torture/execute/string-opt-12.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strcspn.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 Free Software Foundation.
+/* Copyright (C) 2000, 2004 Free Software Foundation.
Ensure all expected transformations of builtin strcspn occur and
perform correctly.
@@ -10,7 +10,8 @@ typedef __SIZE_TYPE__ size_t;
extern size_t strcspn (const char *, const char *);
extern char *strcpy (char *, const char *);
-int main ()
+void
+main_test (void)
{
const char *const s1 = "hello world";
char dst[64], *d2;
@@ -50,18 +51,4 @@ int main ()
to ensure that it works and that the prototype is correct. */
if (__builtin_strcspn (s1, "z") != 11)
abort();
-
- return 0;
-}
-
-#ifdef __OPTIMIZE__
-/* When optimizing, all the above cases should be transformed into
- something else. So any remaining calls to the original function
- should abort. */
-__attribute__ ((noinline))
-static size_t
-strcspn (const char *s1, const char *s2)
-{
- abort();
}
-#endif
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-1-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/string-1-lib.c
deleted file mode 100644
index c9d8b8d..0000000
--- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-1-lib.c
+++ /dev/null
@@ -1,3 +0,0 @@
-#include "lib/strrchr.c"
-#include "lib/strlen.c"
-#include "lib/strcmp.c"
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-1.c b/gcc/testsuite/gcc.c-torture/execute/builtins/string-1.c
deleted file mode 100644
index 8a60e7e..0000000
--- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-1.c
+++ /dev/null
@@ -1,87 +0,0 @@
-/* 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 ();
-}
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-6.c b/gcc/testsuite/gcc.c-torture/execute/builtins/string-6.c
deleted file mode 100644
index 869dba1..0000000
--- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-6.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/* 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
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-8-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strlen-2-lib.c
index 9753c24..9753c24 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-8-lib.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strlen-2-lib.c
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-8.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strlen-2.c
index 220b6ed..29569b7 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-8.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strlen-2.c
@@ -8,7 +8,6 @@ typedef __SIZE_TYPE__ size_t;
extern char *strcpy (char *, const char *);
extern int memcmp (const void *, const void *, size_t);
extern void abort (void);
-extern void exit (int);
extern int inside_main;
size_t g, h, i, j, k, l;
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strlen-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strlen-lib.c
new file mode 100644
index 0000000..9753c24
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strlen-lib.c
@@ -0,0 +1 @@
+#include "lib/strlen.c"
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strlen.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strlen.c
new file mode 100644
index 0000000..cf77294
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strlen.c
@@ -0,0 +1,64 @@
+/* Copyright (C) 2000, 2001, 2003, 2004 Free Software Foundation.
+
+ Ensure all expected transformations of builtin strlen
+ occur and perform correctly.
+
+ Written by Jakub Jelinek, 11/7/2000.
+
+ Additional tests written by Roger Sayle, 11/02/2001:
+ Ensure all builtin strlen comparisons against zero are optimized
+ and perform correctly. The multiple calls to strcpy are to prevent
+ the potentially "pure" strlen calls from being removed by CSE. */
+
+extern void abort (void);
+extern __SIZE_TYPE__ strlen (const char *);
+extern char *strcpy (char *, const char *);
+
+int x = 6;
+
+void
+main_test(void)
+{
+ const char *const foo = "hello world";
+ char str[8];
+ char *ptr;
+
+ if (strlen (foo) != 11)
+ abort ();
+ if (strlen (foo + 4) != 7)
+ abort ();
+ if (strlen (foo + (x++ & 7)) != 5)
+ abort ();
+ if (x != 7)
+ abort ();
+
+ ptr = str;
+ strcpy (ptr, "nts");
+ if (strlen (ptr) == 0)
+ abort ();
+
+ strcpy (ptr, "nts");
+ if (strlen (ptr) < 1)
+ abort ();
+
+ strcpy (ptr, "nts");
+ if (strlen (ptr) <= 0)
+ abort ();
+
+ strcpy (ptr, "nts");
+ if (strlen (ptr+3) != 0)
+ abort ();
+
+ strcpy (ptr, "nts");
+ if (strlen (ptr+3) > 0)
+ abort ();
+
+ strcpy (ptr, "nts");
+ if (strlen (str+3) >= 1)
+ 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_strlen (foo) != 11)
+ abort ();
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strncat-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strncat-lib.c
new file mode 100644
index 0000000..1405a48
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strncat-lib.c
@@ -0,0 +1 @@
+#include "lib/strncat.c"
diff --git a/gcc/testsuite/gcc.c-torture/execute/string-opt-10.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strncat.c
index b883dd6..2ef0e01 100644
--- a/gcc/testsuite/gcc.c-torture/execute/string-opt-10.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strncat.c
@@ -12,7 +12,8 @@ extern char *strcpy (char *, const char *);
extern int strcmp (const char *, const char *);
int x = 123;
-int main ()
+void
+main_test (void)
{
const char *const s1 = "hello world";
const char *const s2 = "";
@@ -68,18 +69,4 @@ int main ()
strcpy (dst, s1);
if (__builtin_strncat (dst, "", 100) != dst || strcmp (dst, s1))
abort();
-
- return 0;
-}
-
-#ifdef __OPTIMIZE__
-/* When optimizing, all the above cases should be transformed into
- something else. So any remaining calls to the original function
- should abort. */
-__attribute__ ((noinline))
-static char *
-strncat (char *s1, const char *s2, size_t n)
-{
- abort();
}
-#endif
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strncmp-2-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strncmp-2-lib.c
new file mode 100644
index 0000000..266c4a4
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strncmp-2-lib.c
@@ -0,0 +1 @@
+#include "lib/strncmp.c"
diff --git a/gcc/testsuite/gcc.c-torture/execute/string-opt-8.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strncmp-2.c
index 2316fce..c9d7878 100644
--- a/gcc/testsuite/gcc.c-torture/execute/string-opt-8.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strncmp-2.c
@@ -9,62 +9,13 @@ extern void abort (void);
typedef __SIZE_TYPE__ size_t;
extern int strncmp (const char *, const char *, size_t);
-int main ()
+void
+main_test (void)
{
const char *const s1 = "hello world";
const char *s2, *s3;
int n = 6, x;
- if (strncmp (s1, "hello world", 12) != 0)
- abort();
- if (strncmp ("hello world", s1, 12) != 0)
- abort();
- if (strncmp ("hello", "hello", 6) != 0)
- abort();
- if (strncmp ("hello", "hello", 2) != 0)
- abort();
- if (strncmp ("hello", "hello", 100) != 0)
- abort();
- if (strncmp (s1+10, "d", 100) != 0)
- abort();
- if (strncmp (10+s1, "d", 100) != 0)
- abort();
- if (strncmp ("d", s1+10, 1) != 0)
- abort();
- if (strncmp ("d", 10+s1, 1) != 0)
- abort();
- if (strncmp ("hello", "aaaaa", 100) <= 0)
- abort();
- if (strncmp ("aaaaa", "hello", 100) >= 0)
- abort();
- if (strncmp ("hello", "aaaaa", 1) <= 0)
- abort();
- if (strncmp ("aaaaa", "hello", 1) >= 0)
- abort();
-
- s2 = s1; s3 = s1+4;
- if (strncmp (++s2, ++s3, 0) != 0 || s2 != s1+1 || s3 != s1+5)
- abort();
- s2 = s1;
- if (strncmp (++s2, "", 1) <= 0 || s2 != s1+1)
- abort();
- if (strncmp ("", ++s2, 1) >= 0 || s2 != s1+2)
- abort();
- if (strncmp (++s2, "", 100) <= 0 || s2 != s1+3)
- abort();
- if (strncmp ("", ++s2, 100) >= 0 || s2 != s1+4)
- abort();
- if (strncmp (++s2+6, "", 100) != 0 || s2 != s1+5)
- abort();
- if (strncmp ("", ++s2+5, 100) != 0 || s2 != s1+6)
- abort();
- if (strncmp ("ozz", ++s2, 1) != 0 || s2 != s1+7)
- abort();
- if (strncmp (++s2, "rzz", 1) != 0 || s2 != s1+8)
- abort();
- s2 = s1; s3 = s1+4;
- if (strncmp (++s2, ++s3+2, 1) >= 0 || s2 != s1+1 || s3 != s1+5)
- abort();
#if !defined(__OPTIMIZE__) || (defined(__i386__) && !defined(__OPTIMIZE_SIZE__))
/* These tests work on platforms which support cmpstrsi. We test it
at -O0 on all platforms to ensure the strncmp logic is correct. */
@@ -219,23 +170,4 @@ int main ()
abort();
#endif
-
- /* 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_strncmp ("hello", "a", 100) <= 0)
- abort();
-
- return 0;
-}
-
-#ifdef __OPTIMIZE__
-/* When optimizing, all the above cases should be transformed into
- something else. So any remaining calls to the original function
- should abort. */
-__attribute__ ((noinline))
-static int
-strncmp(const char *s1, const char *s2, size_t n)
-{
- abort();
}
-#endif
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strncmp-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strncmp-lib.c
new file mode 100644
index 0000000..266c4a4
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strncmp-lib.c
@@ -0,0 +1 @@
+#include "lib/strncmp.c"
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strncmp.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strncmp.c
new file mode 100644
index 0000000..888faf5
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strncmp.c
@@ -0,0 +1,74 @@
+/* Copyright (C) 2000, 2001, 2003 Free Software Foundation.
+
+ Ensure all expected transformations of builtin strncmp occur and
+ perform correctly.
+
+ Written by Kaveh R. Ghazi, 11/26/2000. */
+
+extern void abort (void);
+typedef __SIZE_TYPE__ size_t;
+extern int strncmp (const char *, const char *, size_t);
+
+void
+main_test (void)
+{
+ const char *const s1 = "hello world";
+ const char *s2, *s3;
+ int n = 6, x;
+
+ if (strncmp (s1, "hello world", 12) != 0)
+ abort();
+ if (strncmp ("hello world", s1, 12) != 0)
+ abort();
+ if (strncmp ("hello", "hello", 6) != 0)
+ abort();
+ if (strncmp ("hello", "hello", 2) != 0)
+ abort();
+ if (strncmp ("hello", "hello", 100) != 0)
+ abort();
+ if (strncmp (s1+10, "d", 100) != 0)
+ abort();
+ if (strncmp (10+s1, "d", 100) != 0)
+ abort();
+ if (strncmp ("d", s1+10, 1) != 0)
+ abort();
+ if (strncmp ("d", 10+s1, 1) != 0)
+ abort();
+ if (strncmp ("hello", "aaaaa", 100) <= 0)
+ abort();
+ if (strncmp ("aaaaa", "hello", 100) >= 0)
+ abort();
+ if (strncmp ("hello", "aaaaa", 1) <= 0)
+ abort();
+ if (strncmp ("aaaaa", "hello", 1) >= 0)
+ abort();
+
+ s2 = s1; s3 = s1+4;
+ if (strncmp (++s2, ++s3, 0) != 0 || s2 != s1+1 || s3 != s1+5)
+ abort();
+ s2 = s1;
+ if (strncmp (++s2, "", 1) <= 0 || s2 != s1+1)
+ abort();
+ if (strncmp ("", ++s2, 1) >= 0 || s2 != s1+2)
+ abort();
+ if (strncmp (++s2, "", 100) <= 0 || s2 != s1+3)
+ abort();
+ if (strncmp ("", ++s2, 100) >= 0 || s2 != s1+4)
+ abort();
+ if (strncmp (++s2+6, "", 100) != 0 || s2 != s1+5)
+ abort();
+ if (strncmp ("", ++s2+5, 100) != 0 || s2 != s1+6)
+ abort();
+ if (strncmp ("ozz", ++s2, 1) != 0 || s2 != s1+7)
+ abort();
+ if (strncmp (++s2, "rzz", 1) != 0 || s2 != s1+8)
+ abort();
+ s2 = s1; s3 = s1+4;
+ if (strncmp (++s2, ++s3+2, 1) >= 0 || s2 != s1+1 || s3 != s1+5)
+ 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_strncmp ("hello", "a", 100) <= 0)
+ abort();
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strncpy-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strncpy-lib.c
new file mode 100644
index 0000000..784f72d
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strncpy-lib.c
@@ -0,0 +1 @@
+#include "lib/strncpy.c"
diff --git a/gcc/testsuite/gcc.c-torture/execute/string-opt-7.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strncpy.c
index 5b915d7..c0a8157 100644
--- a/gcc/testsuite/gcc.c-torture/execute/string-opt-7.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strncpy.c
@@ -14,7 +14,8 @@ extern void *memset (void *, int, size_t);
int i;
-int main ()
+void
+main_test (void)
{
const char *const src = "hello world";
const char *src2;
@@ -72,15 +73,3 @@ int main ()
return 0;
}
-
-#ifdef __OPTIMIZE__
-/* When optimizing, all the above cases should be transformed into
- something else. So any remaining calls to the original function
- should abort. */
-__attribute__ ((noinline))
-static char *
-strncpy(char *s1, const char *s2, size_t n)
-{
- abort();
-}
-#endif
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strpbrk-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strpbrk-lib.c
new file mode 100644
index 0000000..66bf8be
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strpbrk-lib.c
@@ -0,0 +1 @@
+#include "lib/strpbrk.c"
diff --git a/gcc/testsuite/gcc.c-torture/execute/string-opt-2.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strpbrk.c
index d8ebb77..cc963a9 100644
--- a/gcc/testsuite/gcc.c-torture/execute/string-opt-2.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strpbrk.c
@@ -34,22 +34,9 @@ void fn (const char *foo, const char *const *bar)
abort();
}
-int main()
+void
+main_test (void)
{
const char *const foo[] = { "hello world", "bye bye world" };
fn (foo[0], foo + 1);
- return 0;
}
-
-
-#ifdef __OPTIMIZE__
-/* When optimizing, all the above cases should be transformed into
- something else. So any remaining calls to the original function
- should abort. */
-__attribute__ ((noinline))
-static char *
-strpbrk(const char *s1, const char *s2)
-{
- abort();
-}
-#endif
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strpcpy-2-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strpcpy-2-lib.c
new file mode 100644
index 0000000..b31cdf4
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strpcpy-2-lib.c
@@ -0,0 +1 @@
+#include "lib/stpcpy.c"
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strpcpy-2.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strpcpy-2.c
new file mode 100644
index 0000000..eb275c4
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strpcpy-2.c
@@ -0,0 +1,45 @@
+/* Copyright (C) 2003 Free Software Foundation.
+
+ Ensure that builtin stpcpy performs correctly.
+
+ Written by Jakub Jelinek, 21/05/2003. */
+
+extern void abort (void);
+typedef __SIZE_TYPE__ size_t;
+extern int memcmp (const void *, const void *, size_t);
+extern char *stpcpy (char *, const char *);
+extern int inside_main;
+
+long buf1[64];
+char *buf2 = (char *) (buf1 + 32);
+long buf5[20];
+char buf7[20];
+
+void
+__attribute__((noinline))
+test (long *buf3, char *buf4, char *buf6, int n)
+{
+ int i = 4;
+
+ if (stpcpy ((char *) buf3, "abcdefghijklmnop") != (char *) buf1 + 16
+ || memcmp (buf1, "abcdefghijklmnop", 17))
+ abort ();
+
+ if (__builtin_stpcpy ((char *) buf3, "ABCDEFG") != (char *) buf1 + 7
+ || memcmp (buf1, "ABCDEFG\0ijklmnop", 17))
+ abort ();
+
+ if (stpcpy ((char *) buf3 + i++, "x") != (char *) buf1 + 5
+ || memcmp (buf1, "ABCDx\0G\0ijklmnop", 17))
+ abort ();
+}
+
+void
+main_test (void)
+{
+ /* All these tests are allowed to call mempcpy/stpcpy. */
+ inside_main = 0;
+ __builtin_memcpy (buf5, "RSTUVWXYZ0123456789", 20);
+ __builtin_memcpy (buf7, "RSTUVWXYZ0123456789", 20);
+ test (buf1, buf2, "rstuvwxyz", 0);
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strpcpy-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strpcpy-lib.c
new file mode 100644
index 0000000..b31cdf4
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strpcpy-lib.c
@@ -0,0 +1 @@
+#include "lib/stpcpy.c"
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strpcpy.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strpcpy.c
new file mode 100644
index 0000000..737bfaa
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strpcpy.c
@@ -0,0 +1,60 @@
+/* Copyright (C) 2003, 2004 Free Software Foundation.
+
+ Ensure builtin stpcpy performs correctly.
+
+ Written by Kaveh Ghazi, 4/11/2003. */
+
+typedef __SIZE_TYPE__ size_t;
+
+extern void abort (void);
+extern char *strcpy (char *, const char *);
+extern char *stpcpy (char *, const char *);
+extern int memcmp (const void *, const void *, size_t);
+
+extern int inside_main;
+
+const char s1[] = "123";
+char p[32] = "";
+char *s2 = "defg";
+char *s3 = "FGH";
+size_t l1 = 1;
+
+void
+main_test (void)
+{
+ int i = 8;
+
+#if !defined __i386__ && !defined __x86_64__
+ /* The functions below might not be optimized into direct stores on all
+ arches. It depends on how many instructions would be generated and
+ what limits the architecture chooses in STORE_BY_PIECES_P. */
+ inside_main = 0;
+#endif
+ 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 (stpcpy ((i++, p + 20 + 1), "23") != (p + 20 + 1 + 2)
+ || i != 9 || memcmp (p + 19, "z\0""23\0", 5))
+ abort ();
+
+ if (stpcpy (stpcpy (p, "ABCD"), "EFG") != p + 7 || 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 the result of stpcpy is ignored, gcc should use strcpy.
+ This should be optimized always, so set inside_main again. */
+ inside_main = 1;
+ stpcpy (p + 3, s3);
+ if (memcmp (p, "abcFGH", 6))
+ abort ();
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strrchr-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strrchr-lib.c
new file mode 100644
index 0000000..90475ec
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strrchr-lib.c
@@ -0,0 +1 @@
+#include "lib/strrchr.c"
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strrchr.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strrchr.c
new file mode 100644
index 0000000..3cc8faa
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strrchr.c
@@ -0,0 +1,49 @@
+/* Copyright (C) 2000, 2003, 2004 Free Software Foundation.
+
+ Ensure all expected transformations of builtin strrchr and rindex
+ occur and perform correctly.
+
+ Written by Jakub Jelinek, 11/7/2000. */
+
+extern void abort (void);
+extern char *strrchr (const char *, int);
+extern char *rindex (const char *, int);
+
+char *bar = "hi world";
+int x = 7;
+
+void
+main_test (void)
+{
+ const char *const foo = "hello world";
+
+ 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_strrchr (foo, 'o') != foo + 7)
+ abort ();
+ if (__builtin_rindex (foo, 'o') != foo + 7)
+ abort ();
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strspn-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strspn-lib.c
new file mode 100644
index 0000000..9e044d7
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strspn-lib.c
@@ -0,0 +1 @@
+#include "lib/strspn.c"
diff --git a/gcc/testsuite/gcc.c-torture/execute/string-opt-11.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strspn.c
index 0aa1862..4f2782a 100644
--- a/gcc/testsuite/gcc.c-torture/execute/string-opt-11.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strspn.c
@@ -10,7 +10,8 @@ typedef __SIZE_TYPE__ size_t;
extern size_t strspn (const char *, const char *);
extern char *strcpy (char *, const char *);
-int main ()
+void
+main_test (void)
{
const char *const s1 = "hello world";
char dst[64], *d2;
@@ -50,18 +51,4 @@ int main ()
to ensure that it works and that the prototype is correct. */
if (__builtin_strspn (s1, "hello") != 5)
abort();
-
- return 0;
-}
-
-#ifdef __OPTIMIZE__
-/* When optimizing, all the above cases should be transformed into
- something else. So any remaining calls to the original function
- should abort. */
-__attribute__ ((noinline))
-static size_t
-strspn (const char *s1, const char *s2)
-{
- abort();
}
-#endif
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-asm-1-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strstr-asm-lib.c
index a031821..a031821 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-asm-1-lib.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strstr-asm-lib.c
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-asm-1.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strstr-asm.c
index 3c3e45d..3c3e45d 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-asm-1.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strstr-asm.c
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strstr-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strstr-lib.c
new file mode 100644
index 0000000..591058d
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strstr-lib.c
@@ -0,0 +1 @@
+#include "lib/strstr.c"
diff --git a/gcc/testsuite/gcc.c-torture/execute/string-opt-1.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strstr.c
index 6b59c10..ae503aa 100644
--- a/gcc/testsuite/gcc.c-torture/execute/string-opt-1.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strstr.c
@@ -8,7 +8,8 @@
extern void abort(void);
extern char *strstr (const char *, const char *);
-int main()
+void
+main_test (void)
{
const char *const foo = "hello world";
@@ -29,18 +30,4 @@ int main()
to ensure that it works and that the prototype is correct. */
if (__builtin_strstr (foo + 1, "world") != foo + 6)
abort();
-
- return 0;
-}
-
-#ifdef __OPTIMIZE__
-/* When optimizing, all the above cases should be transformed into
- something else. So any remaining calls to the original function
- should abort. */
-__attribute__ ((noinline))
-static char *
-strstr(const char *s1, const char *s2)
-{
- abort();
}
-#endif
diff --git a/gcc/testsuite/gcc.c-torture/execute/string-opt-13.c b/gcc/testsuite/gcc.c-torture/execute/string-opt-13.c
deleted file mode 100644
index 9d79ef0..0000000
--- a/gcc/testsuite/gcc.c-torture/execute/string-opt-13.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/* Copyright (C) 2001 Free Software Foundation.
-
- Ensure all builtin strlen comparisons against zero are optimized
- and perform correctly. The multiple calls to strcpy are to prevent
- the potentially "pure" strlen calls from being removed by CSE.
-
- Written by Roger Sayle, 11/02/2001. */
-
-extern void abort (void);
-typedef __SIZE_TYPE__ size_t;
-extern size_t strlen (const char *);
-extern char *strcpy (char *, const char *);
-
-int
-main ()
-{
- char str[8];
- char *ptr;
-
- ptr = str;
- strcpy (ptr, "nts");
- if (strlen (ptr) == 0)
- abort ();
-
- strcpy (ptr, "nts");
- if (strlen (ptr) < 1)
- abort ();
-
- strcpy (ptr, "nts");
- if (strlen (ptr) <= 0)
- abort ();
-
- strcpy (ptr, "nts");
- if (strlen (ptr+3) != 0)
- abort ();
-
- strcpy (ptr, "nts");
- if (strlen (ptr+3) > 0)
- abort ();
-
- strcpy (ptr, "nts");
- if (strlen (str+3) >= 1)
- abort ();
-
- return 0;
-}
-
-#ifdef __OPTIMIZE__
-/* When optimizing, all the above cases should be transformed into
- something else. So any remaining calls to the original function
- should abort. */
-__attribute__ ((noinline))
-static size_t
-strlen (const char *s)
-{
- abort ();
-}
-#endif
-
diff --git a/gcc/testsuite/gcc.c-torture/execute/string-opt-14.c b/gcc/testsuite/gcc.c-torture/execute/string-opt-14.c
deleted file mode 100644
index cb0bfcb..0000000
--- a/gcc/testsuite/gcc.c-torture/execute/string-opt-14.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/* Copyright (C) 2001 Free Software Foundation.
-
- Ensure builtin memset and memcpy are optimized away correctly.
-
- Written by Roger Sayle, 11/23/2001. */
-
-extern void abort (void);
-typedef __SIZE_TYPE__ size_t;
-extern void *memset (void *s, int c, size_t n);
-extern void *memcpy (void *dest, const void *src, size_t n);
-
-char dst[32];
-char src[32];
-
-int
-main ()
-{
- memset (src, 0, 0);
- memcpy (dst, src, 0);
- return 0;
-}
-
-#ifdef __OPTIMIZE__
-/* When optimizing, all the above cases should be transformed into
- something else. So any remaining calls to the original function
- should abort. */
-
-__attribute__ ((noinline))
-static void *
-memset (void *s, int c, size_t n)
-{
- abort ();
-}
-
-__attribute__ ((noinline))
-static void *
-memcpy (void *dest, const void *src, size_t n)
-{
- abort ();
-}
-#endif
-