From: Zack Weinberg Date: Sat, 3 Jul 2004 02:16:50 +0000 (+0000) Subject: * gcc.c-torture/execute/builtin-abs-1.c X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=50c6431753ab7961b4330c5f3c7e611ad81e9178;p=gcc.git * 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 --- diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8638c0ed646..2ba74a1b3dd 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,131 @@ +2004-07-02 Zack Weinberg + + * 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. + 2004-07-02 Mark Mitchell PR c++/16240 diff --git a/gcc/testsuite/gcc.c-torture/execute/builtin-abs-1.c b/gcc/testsuite/gcc.c-torture/execute/builtin-abs-1.c deleted file mode 100644 index 8a34353763d..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/builtin-abs-1.c +++ /dev/null @@ -1,160 +0,0 @@ -/* Test for builtin abs, labs, llabs, imaxabs. */ -/* Origin: Joseph Myers */ - -/* These next definitions are kludges. When GCC has a it - should be used. -*/ -#include -#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 - -extern int abs (int); -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_failure (void); - -int -main (void) -{ - /* For each type, test both runtime and compile time (constant folding) - optimization. */ - volatile int i0 = 0, i1 = 1, im1 = -1, imin = -INT_MAX, imax = INT_MAX; - volatile long l0 = 0L, l1 = 1L, lm1 = -1L, lmin = -LONG_MAX, lmax = LONG_MAX; - volatile long long ll0 = 0LL, ll1 = 1LL, llm1 = -1LL; - volatile long long llmin = -__LONG_LONG_MAX__, llmax = __LONG_LONG_MAX__; - volatile intmax_t imax0 = 0, imax1 = 1, imaxm1 = -1; - volatile intmax_t imaxmin = -INTMAX_MAX, imaxmax = INTMAX_MAX; - if (abs (i0) != 0) - abort (); - if (abs (0) != 0) - link_failure (); - if (abs (i1) != 1) - abort (); - if (abs (1) != 1) - link_failure (); - if (abs (im1) != 1) - abort (); - if (abs (-1) != 1) - link_failure (); - if (abs (imin) != INT_MAX) - abort (); - if (abs (-INT_MAX) != INT_MAX) - link_failure (); - if (abs (imax) != INT_MAX) - abort (); - if (abs (INT_MAX) != INT_MAX) - link_failure (); - if (labs (l0) != 0L) - abort (); - if (labs (0L) != 0L) - link_failure (); - if (labs (l1) != 1L) - abort (); - if (labs (1L) != 1L) - link_failure (); - if (labs (lm1) != 1L) - abort (); - if (labs (-1L) != 1L) - link_failure (); - if (labs (lmin) != LONG_MAX) - abort (); - if (labs (-LONG_MAX) != LONG_MAX) - link_failure (); - if (labs (lmax) != LONG_MAX) - abort (); - if (labs (LONG_MAX) != LONG_MAX) - link_failure (); - if (llabs (ll0) != 0LL) - abort (); - if (llabs (0LL) != 0LL) - link_failure (); - if (llabs (ll1) != 1LL) - abort (); - if (llabs (1LL) != 1LL) - link_failure (); - if (llabs (llm1) != 1LL) - abort (); - if (llabs (-1LL) != 1LL) - link_failure (); - if (llabs (llmin) != __LONG_LONG_MAX__) - abort (); - if (llabs (-__LONG_LONG_MAX__) != __LONG_LONG_MAX__) - link_failure (); - if (llabs (llmax) != __LONG_LONG_MAX__) - abort (); - if (llabs (__LONG_LONG_MAX__) != __LONG_LONG_MAX__) - link_failure (); - if (imaxabs (imax0) != 0) - abort (); - if (imaxabs (0) != 0) - link_failure (); - if (imaxabs (imax1) != 1) - abort (); - if (imaxabs (1) != 1) - link_failure (); - if (imaxabs (imaxm1) != 1) - abort (); - if (imaxabs (-1) != 1) - link_failure (); - if (imaxabs (imaxmin) != INTMAX_MAX) - abort (); - if (imaxabs (-INTMAX_MAX) != INTMAX_MAX) - link_failure (); - 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 (); -} - -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/builtin-abs-2.c b/gcc/testsuite/gcc.c-torture/execute/builtin-abs-2.c deleted file mode 100644 index b4e18796560..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/builtin-abs-2.c +++ /dev/null @@ -1,156 +0,0 @@ -/* Test for builtin abs, labs, llabs, imaxabs. Test for __builtin versions. */ -/* Origin: Joseph Myers */ - -/* These next definitions are kludges. When GCC has a it - should be used. -*/ -#include -#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 - -extern void abort (void); -extern void exit (int); - -extern void link_failure (void); - -int -main (void) -{ - /* For each type, test both runtime and compile time (constant folding) - optimization. */ - volatile int i0 = 0, i1 = 1, im1 = -1, imin = -INT_MAX, imax = INT_MAX; - volatile long l0 = 0L, l1 = 1L, lm1 = -1L, lmin = -LONG_MAX, lmax = LONG_MAX; - volatile long long ll0 = 0LL, ll1 = 1LL, llm1 = -1LL; - volatile long long llmin = -__LONG_LONG_MAX__, llmax = __LONG_LONG_MAX__; - volatile intmax_t imax0 = 0, imax1 = 1, imaxm1 = -1; - volatile intmax_t imaxmin = -INTMAX_MAX, imaxmax = INTMAX_MAX; - if (__builtin_abs (i0) != 0) - abort (); - if (__builtin_abs (0) != 0) - link_failure (); - if (__builtin_abs (i1) != 1) - abort (); - if (__builtin_abs (1) != 1) - link_failure (); - if (__builtin_abs (im1) != 1) - abort (); - if (__builtin_abs (-1) != 1) - link_failure (); - if (__builtin_abs (imin) != INT_MAX) - abort (); - if (__builtin_abs (-INT_MAX) != INT_MAX) - link_failure (); - if (__builtin_abs (imax) != INT_MAX) - abort (); - if (__builtin_abs (INT_MAX) != INT_MAX) - link_failure (); - if (__builtin_labs (l0) != 0L) - abort (); - if (__builtin_labs (0L) != 0L) - link_failure (); - if (__builtin_labs (l1) != 1L) - abort (); - if (__builtin_labs (1L) != 1L) - link_failure (); - if (__builtin_labs (lm1) != 1L) - abort (); - if (__builtin_labs (-1L) != 1L) - link_failure (); - if (__builtin_labs (lmin) != LONG_MAX) - abort (); - if (__builtin_labs (-LONG_MAX) != LONG_MAX) - link_failure (); - if (__builtin_labs (lmax) != LONG_MAX) - abort (); - if (__builtin_labs (LONG_MAX) != LONG_MAX) - link_failure (); - if (__builtin_llabs (ll0) != 0LL) - abort (); - if (__builtin_llabs (0LL) != 0LL) - link_failure (); - if (__builtin_llabs (ll1) != 1LL) - abort (); - if (__builtin_llabs (1LL) != 1LL) - link_failure (); - if (__builtin_llabs (llm1) != 1LL) - abort (); - if (__builtin_llabs (-1LL) != 1LL) - link_failure (); - if (__builtin_llabs (llmin) != __LONG_LONG_MAX__) - abort (); - if (__builtin_llabs (-__LONG_LONG_MAX__) != __LONG_LONG_MAX__) - link_failure (); - if (__builtin_llabs (llmax) != __LONG_LONG_MAX__) - abort (); - if (__builtin_llabs (__LONG_LONG_MAX__) != __LONG_LONG_MAX__) - link_failure (); - if (__builtin_imaxabs (imax0) != 0) - abort (); - if (__builtin_imaxabs (0) != 0) - link_failure (); - if (__builtin_imaxabs (imax1) != 1) - abort (); - if (__builtin_imaxabs (1) != 1) - link_failure (); - if (__builtin_imaxabs (imaxm1) != 1) - abort (); - if (__builtin_imaxabs (-1) != 1) - link_failure (); - if (__builtin_imaxabs (imaxmin) != INTMAX_MAX) - abort (); - if (__builtin_imaxabs (-INTMAX_MAX) != INTMAX_MAX) - link_failure (); - 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 (); -} - -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/builtin-complex-1.c b/gcc/testsuite/gcc.c-torture/execute/builtin-complex-1.c deleted file mode 100644 index 46ab7c51c0f..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/builtin-complex-1.c +++ /dev/null @@ -1,175 +0,0 @@ -/* Test for builtin conj, creal, cimag. */ -/* Origin: Joseph Myers */ - -extern float _Complex conjf (float _Complex); -extern double _Complex conj (double _Complex); -extern long double _Complex conjl (long double _Complex); - -extern float crealf (float _Complex); -extern double creal (double _Complex); -extern long double creall (long double _Complex); - -extern float cimagf (float _Complex); -extern double cimag (double _Complex); -extern long double cimagl (long double _Complex); - -extern void abort (void); -extern void exit (int); - -extern void link_failure (void); - -int -main (void) -{ - /* For each type, test both runtime and compile time (constant folding) - optimization. */ - volatile float _Complex fc = 1.0F + 2.0iF; - volatile double _Complex dc = 1.0 + 2.0i; - volatile long double _Complex ldc = 1.0L + 2.0iL; - /* Test floats. */ - if (conjf (fc) != 1.0F - 2.0iF) - abort (); - if (__builtin_conjf (fc) != 1.0F - 2.0iF) - abort (); - if (conjf (1.0F + 2.0iF) != 1.0F - 2.0iF) - link_failure (); - if (__builtin_conjf (1.0F + 2.0iF) != 1.0F - 2.0iF) - link_failure (); - if (crealf (fc) != 1.0F) - abort (); - if (__builtin_crealf (fc) != 1.0F) - abort (); - if (crealf (1.0F + 2.0iF) != 1.0F) - link_failure (); - if (__builtin_crealf (1.0F + 2.0iF) != 1.0F) - link_failure (); - if (cimagf (fc) != 2.0F) - abort (); - if (__builtin_cimagf (fc) != 2.0F) - abort (); - if (cimagf (1.0F + 2.0iF) != 2.0F) - link_failure (); - if (__builtin_cimagf (1.0F + 2.0iF) != 2.0F) - link_failure (); - /* 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 (); - if (__builtin_conj (1.0 + 2.0i) != 1.0 - 2.0i) - link_failure (); - if (creal (dc) != 1.0) - abort (); - if (__builtin_creal (dc) != 1.0) - abort (); - if (creal (1.0 + 2.0i) != 1.0) - link_failure (); - if (__builtin_creal (1.0 + 2.0i) != 1.0) - link_failure (); - if (cimag (dc) != 2.0) - abort (); - if (__builtin_cimag (dc) != 2.0) - abort (); - if (cimag (1.0 + 2.0i) != 2.0) - link_failure (); - if (__builtin_cimag (1.0 + 2.0i) != 2.0) - link_failure (); - /* 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 (); - if (__builtin_conjl (1.0L + 2.0iL) != 1.0L - 2.0iL) - link_failure (); - if (creall (ldc) != 1.0L) - abort (); - if (__builtin_creall (ldc) != 1.0L) - abort (); - if (creall (1.0L + 2.0iL) != 1.0L) - link_failure (); - if (__builtin_creall (1.0L + 2.0iL) != 1.0L) - link_failure (); - if (cimagl (ldc) != 2.0L) - abort (); - if (__builtin_cimagl (ldc) != 2.0L) - abort (); - if (cimagl (1.0L + 2.0iL) != 2.0L) - link_failure (); - 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 (); -} -#endif 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 1584515af78..6ca246d3922 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 00000000000..494e5390e63 --- /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/builtins/abs-2.c b/gcc/testsuite/gcc.c-torture/execute/builtins/abs-2.c new file mode 100644 index 00000000000..025488d7dd8 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/abs-2.c @@ -0,0 +1,117 @@ +/* Test for builtin abs, labs, llabs, imaxabs. */ +/* Origin: Joseph Myers */ + +/* These next definitions are kludges. When GCC has a it + should be used. +*/ +#include +#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 + +extern int abs (int); +extern long labs (long); +extern long long llabs (long long); +extern intmax_t imaxabs (intmax_t); +extern void abort (void); +extern void link_error (void); + +void +main_test (void) +{ + /* For each type, test both runtime and compile time (constant folding) + optimization. */ + volatile int i0 = 0, i1 = 1, im1 = -1, imin = -INT_MAX, imax = INT_MAX; + volatile long l0 = 0L, l1 = 1L, lm1 = -1L, lmin = -LONG_MAX, lmax = LONG_MAX; + volatile long long ll0 = 0LL, ll1 = 1LL, llm1 = -1LL; + volatile long long llmin = -__LONG_LONG_MAX__, llmax = __LONG_LONG_MAX__; + volatile intmax_t imax0 = 0, imax1 = 1, imaxm1 = -1; + volatile intmax_t imaxmin = -INTMAX_MAX, imaxmax = INTMAX_MAX; + if (abs (i0) != 0) + abort (); + if (abs (0) != 0) + link_error (); + if (abs (i1) != 1) + abort (); + if (abs (1) != 1) + link_error (); + if (abs (im1) != 1) + abort (); + if (abs (-1) != 1) + link_error (); + if (abs (imin) != INT_MAX) + abort (); + if (abs (-INT_MAX) != INT_MAX) + link_error (); + if (abs (imax) != INT_MAX) + abort (); + if (abs (INT_MAX) != INT_MAX) + link_error (); + if (labs (l0) != 0L) + abort (); + if (labs (0L) != 0L) + link_error (); + if (labs (l1) != 1L) + abort (); + if (labs (1L) != 1L) + link_error (); + if (labs (lm1) != 1L) + abort (); + if (labs (-1L) != 1L) + link_error (); + if (labs (lmin) != LONG_MAX) + abort (); + if (labs (-LONG_MAX) != LONG_MAX) + link_error (); + if (labs (lmax) != LONG_MAX) + abort (); + if (labs (LONG_MAX) != LONG_MAX) + link_error (); + if (llabs (ll0) != 0LL) + abort (); + if (llabs (0LL) != 0LL) + link_error (); + if (llabs (ll1) != 1LL) + abort (); + if (llabs (1LL) != 1LL) + link_error (); + if (llabs (llm1) != 1LL) + abort (); + if (llabs (-1LL) != 1LL) + link_error (); + if (llabs (llmin) != __LONG_LONG_MAX__) + abort (); + if (llabs (-__LONG_LONG_MAX__) != __LONG_LONG_MAX__) + link_error (); + if (llabs (llmax) != __LONG_LONG_MAX__) + abort (); + if (llabs (__LONG_LONG_MAX__) != __LONG_LONG_MAX__) + link_error (); + if (imaxabs (imax0) != 0) + abort (); + if (imaxabs (0) != 0) + link_error (); + if (imaxabs (imax1) != 1) + abort (); + if (imaxabs (1) != 1) + link_error (); + if (imaxabs (imaxm1) != 1) + abort (); + if (imaxabs (-1) != 1) + link_error (); + if (imaxabs (imaxmin) != INTMAX_MAX) + abort (); + if (imaxabs (-INTMAX_MAX) != INTMAX_MAX) + link_error (); + if (imaxabs (imaxmax) != INTMAX_MAX) + abort (); + if (imaxabs (INTMAX_MAX) != INTMAX_MAX) + link_error (); +} 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 00000000000..494e5390e63 --- /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/builtins/abs-3.c b/gcc/testsuite/gcc.c-torture/execute/builtins/abs-3.c new file mode 100644 index 00000000000..8300a48a64a --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/abs-3.c @@ -0,0 +1,113 @@ +/* Test for builtin abs, labs, llabs, imaxabs. Test for __builtin versions. */ +/* Origin: Joseph Myers */ + +/* These next definitions are kludges. When GCC has a it + should be used. +*/ +#include +#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 + +extern void abort (void); +extern void link_error (void); + +void +main_test (void) +{ + /* For each type, test both runtime and compile time (constant folding) + optimization. */ + volatile int i0 = 0, i1 = 1, im1 = -1, imin = -INT_MAX, imax = INT_MAX; + volatile long l0 = 0L, l1 = 1L, lm1 = -1L, lmin = -LONG_MAX, lmax = LONG_MAX; + volatile long long ll0 = 0LL, ll1 = 1LL, llm1 = -1LL; + volatile long long llmin = -__LONG_LONG_MAX__, llmax = __LONG_LONG_MAX__; + volatile intmax_t imax0 = 0, imax1 = 1, imaxm1 = -1; + volatile intmax_t imaxmin = -INTMAX_MAX, imaxmax = INTMAX_MAX; + if (__builtin_abs (i0) != 0) + abort (); + if (__builtin_abs (0) != 0) + link_error (); + if (__builtin_abs (i1) != 1) + abort (); + if (__builtin_abs (1) != 1) + link_error (); + if (__builtin_abs (im1) != 1) + abort (); + if (__builtin_abs (-1) != 1) + link_error (); + if (__builtin_abs (imin) != INT_MAX) + abort (); + if (__builtin_abs (-INT_MAX) != INT_MAX) + link_error (); + if (__builtin_abs (imax) != INT_MAX) + abort (); + if (__builtin_abs (INT_MAX) != INT_MAX) + link_error (); + if (__builtin_labs (l0) != 0L) + abort (); + if (__builtin_labs (0L) != 0L) + link_error (); + if (__builtin_labs (l1) != 1L) + abort (); + if (__builtin_labs (1L) != 1L) + link_error (); + if (__builtin_labs (lm1) != 1L) + abort (); + if (__builtin_labs (-1L) != 1L) + link_error (); + if (__builtin_labs (lmin) != LONG_MAX) + abort (); + if (__builtin_labs (-LONG_MAX) != LONG_MAX) + link_error (); + if (__builtin_labs (lmax) != LONG_MAX) + abort (); + if (__builtin_labs (LONG_MAX) != LONG_MAX) + link_error (); + if (__builtin_llabs (ll0) != 0LL) + abort (); + if (__builtin_llabs (0LL) != 0LL) + link_error (); + if (__builtin_llabs (ll1) != 1LL) + abort (); + if (__builtin_llabs (1LL) != 1LL) + link_error (); + if (__builtin_llabs (llm1) != 1LL) + abort (); + if (__builtin_llabs (-1LL) != 1LL) + link_error (); + if (__builtin_llabs (llmin) != __LONG_LONG_MAX__) + abort (); + if (__builtin_llabs (-__LONG_LONG_MAX__) != __LONG_LONG_MAX__) + link_error (); + if (__builtin_llabs (llmax) != __LONG_LONG_MAX__) + abort (); + if (__builtin_llabs (__LONG_LONG_MAX__) != __LONG_LONG_MAX__) + link_error (); + if (__builtin_imaxabs (imax0) != 0) + abort (); + if (__builtin_imaxabs (0) != 0) + link_error (); + if (__builtin_imaxabs (imax1) != 1) + abort (); + if (__builtin_imaxabs (1) != 1) + link_error (); + if (__builtin_imaxabs (imaxm1) != 1) + abort (); + if (__builtin_imaxabs (-1) != 1) + link_error (); + if (__builtin_imaxabs (imaxmin) != INTMAX_MAX) + abort (); + if (__builtin_imaxabs (-INTMAX_MAX) != INTMAX_MAX) + link_error (); + if (__builtin_imaxabs (imaxmax) != INTMAX_MAX) + abort (); + if (__builtin_imaxabs (INTMAX_MAX) != INTMAX_MAX) + link_error (); +} 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 00000000000..22d7db18069 --- /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/builtins/complex-1.c b/gcc/testsuite/gcc.c-torture/execute/builtins/complex-1.c new file mode 100644 index 00000000000..362a0e41ea3 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/complex-1.c @@ -0,0 +1,102 @@ +/* Test for builtin conj, creal, cimag. */ +/* Origin: Joseph Myers */ + +extern float _Complex conjf (float _Complex); +extern double _Complex conj (double _Complex); +extern long double _Complex conjl (long double _Complex); + +extern float crealf (float _Complex); +extern double creal (double _Complex); +extern long double creall (long double _Complex); + +extern float cimagf (float _Complex); +extern double cimag (double _Complex); +extern long double cimagl (long double _Complex); + +extern void abort (void); +extern void link_error (void); + +void +main_test (void) +{ + /* For each type, test both runtime and compile time (constant folding) + optimization. */ + volatile float _Complex fc = 1.0F + 2.0iF; + volatile double _Complex dc = 1.0 + 2.0i; + volatile long double _Complex ldc = 1.0L + 2.0iL; + /* Test floats. */ + if (conjf (fc) != 1.0F - 2.0iF) + abort (); + if (__builtin_conjf (fc) != 1.0F - 2.0iF) + abort (); + if (conjf (1.0F + 2.0iF) != 1.0F - 2.0iF) + link_error (); + if (__builtin_conjf (1.0F + 2.0iF) != 1.0F - 2.0iF) + link_error (); + if (crealf (fc) != 1.0F) + abort (); + if (__builtin_crealf (fc) != 1.0F) + abort (); + if (crealf (1.0F + 2.0iF) != 1.0F) + link_error (); + if (__builtin_crealf (1.0F + 2.0iF) != 1.0F) + link_error (); + if (cimagf (fc) != 2.0F) + abort (); + if (__builtin_cimagf (fc) != 2.0F) + abort (); + if (cimagf (1.0F + 2.0iF) != 2.0F) + link_error (); + if (__builtin_cimagf (1.0F + 2.0iF) != 2.0F) + 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_error (); + if (__builtin_conj (1.0 + 2.0i) != 1.0 - 2.0i) + link_error (); + if (creal (dc) != 1.0) + abort (); + if (__builtin_creal (dc) != 1.0) + abort (); + if (creal (1.0 + 2.0i) != 1.0) + link_error (); + if (__builtin_creal (1.0 + 2.0i) != 1.0) + link_error (); + if (cimag (dc) != 2.0) + abort (); + if (__builtin_cimag (dc) != 2.0) + abort (); + if (cimag (1.0 + 2.0i) != 2.0) + link_error (); + if (__builtin_cimag (1.0 + 2.0i) != 2.0) + 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_error (); + if (__builtin_conjl (1.0L + 2.0iL) != 1.0L - 2.0iL) + link_error (); + if (creall (ldc) != 1.0L) + abort (); + if (__builtin_creall (ldc) != 1.0L) + abort (); + if (creall (1.0L + 2.0iL) != 1.0L) + link_error (); + if (__builtin_creall (1.0L + 2.0iL) != 1.0L) + link_error (); + if (cimagl (ldc) != 2.0L) + abort (); + if (__builtin_cimagl (ldc) != 2.0L) + abort (); + if (cimagl (1.0L + 2.0iL) != 2.0L) + link_error (); + if (__builtin_cimagl (1.0L + 2.0iL) != 2.0L) + link_error (); +} 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 00000000000..b6a1e913da4 --- /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/builtins/fprintf.c b/gcc/testsuite/gcc.c-torture/execute/builtins/fprintf.c new file mode 100644 index 00000000000..6b6e71b78f8 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/fprintf.c @@ -0,0 +1,52 @@ +/* Copyright (C) 2001 Free Software Foundation. + + Ensure all expected transformations of builtin fprintf occur and + that we honor side effects in the arguments. + + Written by Kaveh R. Ghazi, 1/7/2001. */ + +#include +extern void abort(void); + +void +main_test (void) +{ + FILE *s_array[] = {stdout, NULL}, **s_ptr = s_array; + const char *const s1 = "hello world"; + const char *const s2[] = { s1, 0 }, *const*s3; + + fprintf (*s_ptr, "%s", "hello"); + fprintf (*s_ptr, "%s", "\n"); + fprintf (*s_ptr, "%s", *s2); + s3 = s2; + fprintf (*s_ptr, "%s", *s3++); + if (s3 != s2+1 || *s3 != 0) + abort(); + s3 = s2; + fprintf (*s_ptr++, "%s", *s3++); + if (s3 != s2+1 || *s3 != 0 || s_ptr != s_array+1 || *s_ptr != 0) + abort(); + + s_ptr = s_array; + fprintf (*s_ptr, "%c", '\n'); + fprintf (*s_ptr, "%c", **s2); + s3 = s2; + fprintf (*s_ptr, "%c", **s3++); + if (s3 != s2+1 || *s3 != 0) + abort(); + s3 = s2; + fprintf (*s_ptr++, "%c", **s3++); + if (s3 != s2+1 || *s3 != 0 || s_ptr != s_array+1 || *s_ptr != 0) + abort(); + + s_ptr = s_array; + fprintf (*s_ptr++, "hello world"); + if (s_ptr != s_array+1 || *s_ptr != 0) + abort(); + s_ptr = s_array; + fprintf (*s_ptr, "\n"); + + /* 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"); +} 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 00000000000..48a955309c1 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/fputs-lib.c @@ -0,0 +1,17 @@ +#include +#include +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/builtins/fputs.c b/gcc/testsuite/gcc.c-torture/execute/builtins/fputs.c new file mode 100644 index 00000000000..9274d5b643f --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/fputs.c @@ -0,0 +1,61 @@ +/* Copyright (C) 2000, 2001 Free Software Foundation. + + Ensure all expected transformations of builtin fputs occur and that + we honor side effects in the stream argument. + + Written by Kaveh R. Ghazi, 10/30/2000. */ + +#include +extern void abort(void); + +int i; + +void +main_test(void) +{ + FILE *s_array[] = {stdout, NULL}, **s_ptr = s_array; + const char *const s1 = "hello world"; + + fputs ("", *s_ptr); + fputs ("\n", *s_ptr); + fputs ("bye", *s_ptr); + fputs (s1, *s_ptr); + fputs (s1+5, *s_ptr); + fputs (s1+10, *s_ptr); + fputs (s1+11, *s_ptr); + + /* Check side-effects when transforming fputs -> NOP. */ + fputs ("", *s_ptr++); + if (s_ptr != s_array+1 || *s_ptr != 0) + abort(); + + /* Check side-effects when transforming fputs -> fputc. */ + s_ptr = s_array; + fputs ("\n", *s_ptr++); + if (s_ptr != s_array+1 || *s_ptr != 0) + abort(); + + /* Check side-effects when transforming fputs -> fwrite. */ + s_ptr = s_array; + fputs ("hello\n", *s_ptr++); + if (s_ptr != s_array+1 || *s_ptr != 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. */ + s_ptr = s_array; + __builtin_fputs ("", *s_ptr); + /* These builtin stubs are called by __builtin_fputs, ensure their + prototypes are set correctly too. */ + __builtin_fputc ('\n', *s_ptr); + __builtin_fwrite ("hello\n", 1, 6, *s_ptr); + + /* Check side-effects in conditional expression. */ + s_ptr = s_array; + fputs (i++ ? "f" : "x", *s_ptr++); + if (s_ptr != s_array+1 || *s_ptr != 0 || i != 1) + abort(); + fputs (--i ? "\n" : "\n", *--s_ptr); + if (s_ptr != s_array || i != 0) + abort(); +} 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 00000000000..99ca10df393 --- /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 it + should be used. +*/ +#include +#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 00000000000..80c240cc8e7 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/fprintf.c @@ -0,0 +1,18 @@ +#include +#include +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 cfd79baef47..6f3c3170cc1 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/lib/memset.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/memset.c new file mode 100644 index 00000000000..d5326ffeb2b --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/memset.c @@ -0,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; +} 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 00000000000..be2a63bc61e --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/printf.c @@ -0,0 +1,19 @@ +#include +#include +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 00000000000..0c0cd5b9345 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/sprintf.c @@ -0,0 +1,20 @@ +#include +#include +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 00000000000..127b57733c4 --- /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 00000000000..767c89a6351 --- /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 00000000000..59d3cc0ae0a --- /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 00000000000..c0b890677e5 --- /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 00000000000..a96f7cb925f --- /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 00000000000..1eb90ade5fb --- /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 00000000000..29477cc764c --- /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 00000000000..fa43c934312 --- /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/memcmp-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/memcmp-lib.c new file mode 100644 index 00000000000..029a92e77d5 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/memcmp-lib.c @@ -0,0 +1 @@ +#include "lib/memcmp.c" diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/memcmp.c b/gcc/testsuite/gcc.c-torture/execute/builtins/memcmp.c new file mode 100644 index 00000000000..5489048f5f9 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/memcmp.c @@ -0,0 +1,41 @@ +/* Copyright (C) 2001 Free Software Foundation. + + Ensure that short builtin memcmp are optimized and perform correctly. + 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. + 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); + +void +main_test (void) +{ + char str[8]; + + strcpy (str, "3141"); + + if ( memcmp (str, str+2, 0) != 0 ) + abort (); + if ( memcmp (str+1, str+3, 0) != 0 ) + abort (); + + if ( memcmp (str+1, str+3, 1) != 0 ) + abort (); + if ( memcmp (str, str+2, 1) >= 0 ) + abort (); + if ( memcmp (str+2, str, 1) <= 0 ) + abort (); + + if (memcmp ("abcd", "efgh", 4) >= 0) + link_error (); + if (memcmp ("abcd", "abcd", 4) != 0) + link_error (); + if (memcmp ("efgh", "abcd", 4) <= 0) + link_error (); +} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/memmove-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/memmove-lib.c new file mode 100644 index 00000000000..5be3df52fe5 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/memmove-lib.c @@ -0,0 +1 @@ +#include "lib/memmove.c" diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/memmove.c b/gcc/testsuite/gcc.c-torture/execute/builtins/memmove.c new file mode 100644 index 00000000000..4a18fc6400f --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/memmove.c @@ -0,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 (); +} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/memops-asm-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/memops-asm-lib.c new file mode 100644 index 00000000000..16369a21794 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/memops-asm-lib.c @@ -0,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); +} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/memops-asm.c b/gcc/testsuite/gcc.c-torture/execute/builtins/memops-asm.c new file mode 100644 index 00000000000..e793778053a --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/memops-asm.c @@ -0,0 +1,47 @@ +/* Copyright (C) 2003 Free Software Foundation. + + Test memcpy and memset in presence of redirect. */ + +#define ASMNAME(cname) ASMNAME2 (__USER_LABEL_PREFIX__, cname) +#define ASMNAME2(prefix, cname) STRING (prefix) cname +#define STRING(x) #x + +typedef __SIZE_TYPE__ size_t; +extern void abort (void); +extern void *memcpy (void *, const void *, size_t) + __asm (ASMNAME ("my_memcpy")); +extern void bcopy (const void *, void *, size_t) + __asm (ASMNAME ("my_bcopy")); +extern void *memset (void *, int, size_t) + __asm (ASMNAME ("my_memset")); +extern void bzero (void *, size_t) + __asm (ASMNAME ("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 (); +} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/mempcpy-2-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/mempcpy-2-lib.c new file mode 100644 index 00000000000..cf3178c834a --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/mempcpy-2-lib.c @@ -0,0 +1 @@ +#include "lib/mempcpy.c" diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/mempcpy-2.c b/gcc/testsuite/gcc.c-torture/execute/builtins/mempcpy-2.c new file mode 100644 index 00000000000..dcaf07b67f1 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/mempcpy-2.c @@ -0,0 +1,153 @@ +/* Copyright (C) 2003 Free Software Foundation. + + Ensure that builtin mempcpy and stpcpy perform correctly. + + Written by Jakub Jelinek, 21/05/2003. */ + +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 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 = 0; + + /* These should probably be handled by store_by_pieces on most arches. */ + if (mempcpy (buf1, "ABCDEFGHI", 9) != (char *) buf1 + 9 + || memcmp (buf1, "ABCDEFGHI\0", 11)) + abort (); + + if (mempcpy (buf1, "abcdefghijklmnopq", 17) != (char *) buf1 + 17 + || memcmp (buf1, "abcdefghijklmnopq\0", 19)) + abort (); + + if (__builtin_mempcpy (buf3, "ABCDEF", 6) != (char *) buf1 + 6 + || memcmp (buf1, "ABCDEFghijklmnopq\0", 19)) + abort (); + + if (__builtin_mempcpy (buf3, "a", 1) != (char *) buf1 + 1 + || memcmp (buf1, "aBCDEFghijklmnopq\0", 19)) + abort (); + + if (mempcpy ((char *) buf3 + 2, "bcd" + ++i, 2) != (char *) buf1 + 4 + || memcmp (buf1, "aBcdEFghijklmnopq\0", 19) + || i != 1) + abort (); + + /* These should probably be handled by move_by_pieces on most arches. */ + if (mempcpy ((char *) buf3 + 4, buf5, 6) != (char *) buf1 + 10 + || memcmp (buf1, "aBcdRSTUVWklmnopq\0", 19)) + abort (); + + if (__builtin_mempcpy ((char *) buf1 + ++i + 8, (char *) buf5 + 1, 1) + != (char *) buf1 + 11 + || memcmp (buf1, "aBcdRSTUVWSlmnopq\0", 19) + || i != 2) + abort (); + + if (mempcpy ((char *) buf3 + 14, buf6, 2) != (char *) buf1 + 16 + || memcmp (buf1, "aBcdRSTUVWSlmnrsq\0", 19)) + abort (); + + if (mempcpy (buf3, buf5, 8) != (char *) buf1 + 8 + || memcmp (buf1, "RSTUVWXYVWSlmnrsq\0", 19)) + abort (); + + if (mempcpy (buf3, buf5, 17) != (char *) buf1 + 17 + || memcmp (buf1, "RSTUVWXYZ01234567\0", 19)) + abort (); + + __builtin_memcpy (buf3, "aBcdEFghijklmnopq\0", 19); + + /* These should be handled either by movstrendM or mempcpy + call. */ + if (mempcpy ((char *) buf3 + 4, buf5, n + 6) != (char *) buf1 + 10 + || memcmp (buf1, "aBcdRSTUVWklmnopq\0", 19)) + abort (); + + if (__builtin_mempcpy ((char *) buf1 + ++i + 8, (char *) buf5 + 1, n + 1) + != (char *) buf1 + 12 + || memcmp (buf1, "aBcdRSTUVWkSmnopq\0", 19) + || i != 3) + abort (); + + if (mempcpy ((char *) buf3 + 14, buf6, n + 2) != (char *) buf1 + 16 + || memcmp (buf1, "aBcdRSTUVWkSmnrsq\0", 19)) + abort (); + + i = 1; + + /* These might be handled by store_by_pieces. */ + if (mempcpy (buf2, "ABCDEFGHI", 9) != buf2 + 9 + || memcmp (buf2, "ABCDEFGHI\0", 11)) + abort (); + + if (mempcpy (buf2, "abcdefghijklmnopq", 17) != buf2 + 17 + || memcmp (buf2, "abcdefghijklmnopq\0", 19)) + abort (); + + if (__builtin_mempcpy (buf4, "ABCDEF", 6) != buf2 + 6 + || memcmp (buf2, "ABCDEFghijklmnopq\0", 19)) + abort (); + + if (__builtin_mempcpy (buf4, "a", 1) != buf2 + 1 + || memcmp (buf2, "aBCDEFghijklmnopq\0", 19)) + abort (); + + if (mempcpy (buf4 + 2, "bcd" + i++, 2) != buf2 + 4 + || memcmp (buf2, "aBcdEFghijklmnopq\0", 19) + || i != 2) + abort (); + + /* These might be handled by move_by_pieces. */ + if (mempcpy (buf4 + 4, buf7, 6) != buf2 + 10 + || memcmp (buf2, "aBcdRSTUVWklmnopq\0", 19)) + abort (); + + if (__builtin_mempcpy (buf2 + i++ + 8, buf7 + 1, 1) + != buf2 + 11 + || memcmp (buf2, "aBcdRSTUVWSlmnopq\0", 19) + || i != 3) + abort (); + + if (mempcpy (buf4 + 14, buf6, 2) != buf2 + 16 + || memcmp (buf2, "aBcdRSTUVWSlmnrsq\0", 19)) + abort (); + + __builtin_memcpy (buf4, "aBcdEFghijklmnopq\0", 19); + + /* These should be handled either by movstrendM or mempcpy + call. */ + if (mempcpy (buf4 + 4, buf7, n + 6) != buf2 + 10 + || memcmp (buf2, "aBcdRSTUVWklmnopq\0", 19)) + abort (); + + if (__builtin_mempcpy (buf2 + i++ + 8, buf7 + 1, n + 1) + != buf2 + 12 + || memcmp (buf2, "aBcdRSTUVWkSmnopq\0", 19) + || i != 4) + abort (); + + if (mempcpy (buf4 + 14, buf6, n + 2) != buf2 + 16 + || memcmp (buf2, "aBcdRSTUVWkSmnrsq\0", 19)) + 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/mempcpy-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/mempcpy-lib.c new file mode 100644 index 00000000000..cf3178c834a --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/mempcpy-lib.c @@ -0,0 +1 @@ +#include "lib/mempcpy.c" diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/mempcpy.c b/gcc/testsuite/gcc.c-torture/execute/builtins/mempcpy.c new file mode 100644 index 00000000000..d82e2232d7b --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/mempcpy.c @@ -0,0 +1,68 @@ +/* Copyright (C) 2003 Free Software Foundation. + + Ensure builtin mempcpy performs correctly. + + Written by Kaveh Ghazi, 4/11/2003. */ + +extern void abort (void); +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); +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; + +#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 (mempcpy (p, "ABCDE", 6) != p + 6 || memcmp (p, "ABCDE", 6)) + abort (); + 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\0CFGHI", 8)) + abort (); + + i = 8; + memcpy (p + 20, "qrstu", 6); + memcpy (p + 25, "QRSTU", 6); + if (mempcpy (p + 25 + 1, s1, 3) != (p + 25 + 1 + 3) + || memcmp (p + 25, "Q123U", 6)) + 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_mempcpy (p, "ABCDE", 6) != p + 6 || memcmp (p, "ABCDE", 6)) + abort (); + + /* If the result of mempcpy is ignored, gcc should use memcpy. + This should be optimized always, so set inside_main again. */ + inside_main = 1; + mempcpy (p + 5, s3, 1); + if (memcmp (p, "ABCDEFg", 8)) + abort (); + 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 00000000000..2eeff38be24 --- /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/memset.c b/gcc/testsuite/gcc.c-torture/execute/builtins/memset.c new file mode 100644 index 00000000000..cf7c1e303e8 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/memset.c @@ -0,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); +} 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 00000000000..45ed7ec3738 --- /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/builtins/printf.c b/gcc/testsuite/gcc.c-torture/execute/builtins/printf.c new file mode 100644 index 00000000000..0d01e544aa1 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/printf.c @@ -0,0 +1,41 @@ +/* Copyright (C) 2000 Free Software Foundation. + + Ensure all expected transformations of builtin printf occur and + that we honor side effects in the arguments. + + Written by Kaveh R. Ghazi, 12/4/2000. */ + +extern int printf (const char *, ...); +extern void abort(void); + +void +main_test (void) +{ + const char *const s1 = "hello world"; + const char *const s2[] = { s1, 0 }, *const*s3; + + printf ("%s\n", "hello"); + printf ("%s\n", *s2); + s3 = s2; + printf ("%s\n", *s3++); + if (s3 != s2+1 || *s3 != 0) + abort(); + + printf ("%c", '\n'); + printf ("%c", **s2); + s3 = s2; + printf ("%c", **s3++); + if (s3 != s2+1 || *s3 != 0) + abort(); + + printf ("\n"); + printf ("hello world\n"); + + /* Test at least one instance of the __builtin_ style. We do this + to ensure that it works and that the prototype is correct. */ + __builtin_printf ("%s\n", "hello"); + /* These builtin stubs are called by __builtin_printf, ensure their + prototypes are set correctly too. */ + __builtin_putchar ('\n'); + __builtin_puts ("hello"); +} 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 00000000000..3a4fe34c0b1 --- /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/builtins/sprintf.c b/gcc/testsuite/gcc.c-torture/execute/builtins/sprintf.c new file mode 100644 index 00000000000..b45926469f6 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/sprintf.c @@ -0,0 +1,71 @@ +/* Copyright (C) 2003 Free Software Foundation. + + Test sprintf optimizations don't break anything and return the + correct results. + + Written by Roger Sayle, June 22, 2003. */ + +static char buffer[32]; + +extern void abort (); +typedef __SIZE_TYPE__ size_t; +extern int sprintf(char*, const char*, ...); +extern void *memset(void*, int, size_t); +extern int memcmp(const void*, const void*, size_t); + +void test1() +{ + sprintf(buffer,"foo"); +} + +int test2() +{ + return sprintf(buffer,"foo"); +} + +void test3() +{ + sprintf(buffer,"%s","bar"); +} + +int test4() +{ + return sprintf(buffer,"%s","bar"); +} + +void test5(char *ptr) +{ + sprintf(buffer,"%s",ptr); +} + + +void +main_test (void) +{ + memset (buffer, 'A', 32); + test1 (); + if (memcmp(buffer, "foo", 4) || buffer[4] != 'A') + abort (); + + memset (buffer, 'A', 32); + if (test2 () != 3) + abort (); + if (memcmp(buffer, "foo", 4) || buffer[4] != 'A') + abort (); + + memset (buffer, 'A', 32); + test3 (); + if (memcmp(buffer, "bar", 4) || buffer[4] != 'A') + abort (); + + memset (buffer, 'A', 32); + if (test4 () != 3) + abort (); + if (memcmp(buffer, "bar", 4) || buffer[4] != 'A') + abort (); + + memset (buffer, 'A', 32); + test5 ("barf"); + if (memcmp(buffer, "barf", 5) || buffer[5] != 'A') + abort (); +} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strcat-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strcat-lib.c new file mode 100644 index 00000000000..0a0bbb8865a --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strcat-lib.c @@ -0,0 +1 @@ +#include "lib/strcat.c" diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strcat.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strcat.c new file mode 100644 index 00000000000..ba70c397724 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strcat.c @@ -0,0 +1,79 @@ +/* Copyright (C) 2000, 2003 Free Software Foundation. + + Ensure all expected transformations of builtin strcat occur and + perform correctly. + + Written by Kaveh R. Ghazi, 11/27/2000. */ + +extern int inside_main; +extern void abort (void); +typedef __SIZE_TYPE__ size_t; +extern char *strcat (char *, const char *); +extern char *strcpy (char *, const char *); +extern int strcmp (const char *, const char *); +extern void *memset (void *, int, size_t); +extern int memcmp (const void *, const void *, size_t); +#define RESET_DST_WITH(FILLER) \ + do { memset (dst, 'X', sizeof (dst)); strcpy (dst, (FILLER)); } while (0) + +void main_test (void) +{ + const char *const s1 = "hello world"; + const char *const s2 = ""; + char dst[64], *d2; + + RESET_DST_WITH (s1); + if (strcat (dst, "") != dst || strcmp (dst, s1)) + abort(); + RESET_DST_WITH (s1); + if (strcat (dst, s2) != dst || strcmp (dst, s1)) + abort(); + RESET_DST_WITH (s1); d2 = dst; + if (strcat (++d2, s2) != dst+1 || d2 != dst+1 || strcmp (dst, s1)) + abort(); + RESET_DST_WITH (s1); d2 = dst; + if (strcat (++d2+5, s2) != dst+6 || d2 != dst+1 || strcmp (dst, s1)) + abort(); + RESET_DST_WITH (s1); d2 = dst; + if (strcat (++d2+5, s1+11) != dst+6 || d2 != dst+1 || strcmp (dst, s1)) + abort(); + +#ifndef __OPTIMIZE_SIZE__ +# 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 + + RESET_DST_WITH (s1); + if (strcat (dst, " 1111") != dst + || memcmp (dst, "hello world 1111\0XXX", 20)) + abort(); + + RESET_DST_WITH (s1); + if (strcat (dst+5, " 2222") != dst+5 + || memcmp (dst, "hello world 2222\0XXX", 20)) + abort(); + + RESET_DST_WITH (s1); d2 = dst; + if (strcat (++d2+5, " 3333") != dst+6 || d2 != dst+1 + || memcmp (dst, "hello world 3333\0XXX", 20)) + abort(); + + RESET_DST_WITH (s1); + strcat (strcat (strcat (strcat (strcat (strcat (dst, ": this "), ""), + "is "), "a "), "test"), "."); + if (memcmp (dst, "hello world: this is a test.\0X", 30)) + abort(); + + /* Set inside_main again. */ + inside_main = 1; +#endif + + /* Test at least one instance of the __builtin_ style. We do this + to ensure that it works and that the prototype is correct. */ + RESET_DST_WITH (s1); + if (__builtin_strcat (dst, "") != dst || strcmp (dst, s1)) + abort(); +} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strchr-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strchr-lib.c new file mode 100644 index 00000000000..9049fb9e1ff --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strchr-lib.c @@ -0,0 +1 @@ +#include "lib/strchr.c" diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strchr.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strchr.c new file mode 100644 index 00000000000..08e87c63d30 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strchr.c @@ -0,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 (); +} 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 00000000000..99c421486e6 --- /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 00000000000..08a7658ea4e --- /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 00000000000..b10dfcb0d79 --- /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/builtins/strcpy.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strcpy.c new file mode 100644 index 00000000000..0ca62b3a2d9 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strcpy.c @@ -0,0 +1,41 @@ +/* Copyright (C) 2000 Free Software Foundation. + + Ensure builtin memcpy and strcpy perform correctly. + + Written by Jakub Jelinek, 11/24/2000. */ + +extern void abort (void); +extern char *strcpy (char *, const char *); +typedef __SIZE_TYPE__ size_t; +extern void *memcpy (void *, const void *, size_t); +extern int memcmp (const void *, const void *, size_t); + +char p[32] = ""; + +void +main_test (void) +{ + if (strcpy (p, "abcde") != p || memcmp (p, "abcde", 6)) + abort (); + if (strcpy (p + 16, "vwxyz" + 1) != p + 16 || memcmp (p + 16, "wxyz", 5)) + abort (); + if (strcpy (p + 1, "") != p + 1 || memcmp (p, "a\0cde", 6)) + abort (); + if (strcpy (p + 3, "fghij") != p + 3 || memcmp (p, "a\0cfghij", 9)) + abort (); + if (memcpy (p, "ABCDE", 6) != p || memcmp (p, "ABCDE", 6)) + abort (); + if (memcpy (p + 16, "VWX" + 1, 2) != p + 16 || memcmp (p + 16, "WXyz", 5)) + abort (); + if (memcpy (p + 1, "", 1) != p + 1 || memcmp (p, "A\0CDE", 6)) + abort (); + if (memcpy (p + 3, "FGHI", 4) != p + 3 || memcmp (p, "A\0CFGHIj", 9)) + 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_strcpy (p, "abcde") != p || memcmp (p, "abcde", 6)) + abort (); + if (__builtin_memcpy (p, "ABCDE", 6) != p || memcmp (p, "ABCDE", 6)) + abort (); +} 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 00000000000..8b1cfea01e8 --- /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/builtins/strcspn.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strcspn.c new file mode 100644 index 00000000000..be392546a54 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strcspn.c @@ -0,0 +1,54 @@ +/* Copyright (C) 2000, 2004 Free Software Foundation. + + Ensure all expected transformations of builtin strcspn occur and + perform correctly. + + Written by Kaveh R. Ghazi, 11/27/2000. */ + +extern void abort (void); +typedef __SIZE_TYPE__ size_t; +extern size_t strcspn (const char *, const char *); +extern char *strcpy (char *, const char *); + +void +main_test (void) +{ + const char *const s1 = "hello world"; + char dst[64], *d2; + + if (strcspn (s1, "hello") != 0) + abort(); + if (strcspn (s1, "z") != 11) + abort(); + if (strcspn (s1+4, "z") != 7) + abort(); + if (strcspn (s1, "hello world") != 0) + abort(); + if (strcspn (s1, "") != 11) + abort(); + strcpy (dst, s1); + if (strcspn (dst, "") != 11) + abort(); + strcpy (dst, s1); d2 = dst; + if (strcspn (++d2, "") != 10 || d2 != dst+1) + abort(); + strcpy (dst, s1); d2 = dst; + if (strcspn (++d2+5, "") != 5 || d2 != dst+1) + abort(); + if (strcspn ("", s1) != 0) + abort(); + strcpy (dst, s1); + if (strcspn ("", dst) != 0) + abort(); + strcpy (dst, s1); d2 = dst; + if (strcspn ("", ++d2) != 0 || d2 != dst+1) + abort(); + strcpy (dst, s1); d2 = dst; + if (strcspn ("", ++d2+5) != 0 || d2 != dst+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_strcspn (s1, "z") != 11) + abort(); +} 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 c9d8b8da7b9..00000000000 --- 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 8a60e7e80ae..00000000000 --- 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-2-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/string-2-lib.c deleted file mode 100644 index 9049fb9e1ff..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-2-lib.c +++ /dev/null @@ -1 +0,0 @@ -#include "lib/strchr.c" diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-2.c b/gcc/testsuite/gcc.c-torture/execute/builtins/string-2.c deleted file mode 100644 index 08e87c63d30..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-2.c +++ /dev/null @@ -1,36 +0,0 @@ -/* 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 (); -} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-3-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/string-3-lib.c deleted file mode 100644 index d5326ffeb2b..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-3-lib.c +++ /dev/null @@ -1,17 +0,0 @@ -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; -} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-3.c b/gcc/testsuite/gcc.c-torture/execute/builtins/string-3.c deleted file mode 100644 index cf7c1e303e8..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-3.c +++ /dev/null @@ -1,36 +0,0 @@ -/* 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); -} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-4-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/string-4-lib.c deleted file mode 100644 index 3b69c3baea8..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-4-lib.c +++ /dev/null @@ -1,2 +0,0 @@ -#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/string-4.c deleted file mode 100644 index 51819b1cfa9..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-4.c +++ /dev/null @@ -1,86 +0,0 @@ -/* 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); -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; - -#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 (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 (); - - memcpy (p + 25, "QRSTU", 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)) - 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. */ - inside_main = 1; - 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 (); -} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-5-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/string-5-lib.c deleted file mode 100644 index 5be3df52fe5..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-5-lib.c +++ /dev/null @@ -1 +0,0 @@ -#include "lib/memmove.c" diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-5.c b/gcc/testsuite/gcc.c-torture/execute/builtins/string-5.c deleted file mode 100644 index 4a18fc6400f..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-5.c +++ /dev/null @@ -1,90 +0,0 @@ -/* 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 (); -} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-6-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/string-6-lib.c deleted file mode 100644 index 029a92e77d5..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-6-lib.c +++ /dev/null @@ -1 +0,0 @@ -#include "lib/memcmp.c" 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 869dba17baa..00000000000 --- 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-7-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/string-7-lib.c deleted file mode 100644 index 3b69c3baea8..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-7-lib.c +++ /dev/null @@ -1,2 +0,0 @@ -#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/string-7.c deleted file mode 100644 index 5eb1ac4af78..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-7.c +++ /dev/null @@ -1,169 +0,0 @@ -/* Copyright (C) 2003 Free Software Foundation. - - Ensure that builtin mempcpy and stpcpy perform correctly. - - Written by Jakub Jelinek, 21/05/2003. */ - -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]; -char *buf2 = (char *) (buf1 + 32); -long buf5[20]; -char buf7[20]; - -int -__attribute__((noinline)) -test (long *buf3, char *buf4, char *buf6, int n) -{ - int i = 0; - - /* These should probably be handled by store_by_pieces on most arches. */ - if (mempcpy (buf1, "ABCDEFGHI", 9) != (char *) buf1 + 9 - || memcmp (buf1, "ABCDEFGHI\0", 11)) - abort (); - - if (mempcpy (buf1, "abcdefghijklmnopq", 17) != (char *) buf1 + 17 - || memcmp (buf1, "abcdefghijklmnopq\0", 19)) - abort (); - - if (__builtin_mempcpy (buf3, "ABCDEF", 6) != (char *) buf1 + 6 - || memcmp (buf1, "ABCDEFghijklmnopq\0", 19)) - abort (); - - if (__builtin_mempcpy (buf3, "a", 1) != (char *) buf1 + 1 - || memcmp (buf1, "aBCDEFghijklmnopq\0", 19)) - abort (); - - if (mempcpy ((char *) buf3 + 2, "bcd" + ++i, 2) != (char *) buf1 + 4 - || memcmp (buf1, "aBcdEFghijklmnopq\0", 19) - || i != 1) - abort (); - - /* These should probably be handled by move_by_pieces on most arches. */ - if (mempcpy ((char *) buf3 + 4, buf5, 6) != (char *) buf1 + 10 - || memcmp (buf1, "aBcdRSTUVWklmnopq\0", 19)) - abort (); - - if (__builtin_mempcpy ((char *) buf1 + ++i + 8, (char *) buf5 + 1, 1) - != (char *) buf1 + 11 - || memcmp (buf1, "aBcdRSTUVWSlmnopq\0", 19) - || i != 2) - abort (); - - if (mempcpy ((char *) buf3 + 14, buf6, 2) != (char *) buf1 + 16 - || memcmp (buf1, "aBcdRSTUVWSlmnrsq\0", 19)) - abort (); - - if (mempcpy (buf3, buf5, 8) != (char *) buf1 + 8 - || memcmp (buf1, "RSTUVWXYVWSlmnrsq\0", 19)) - abort (); - - if (mempcpy (buf3, buf5, 17) != (char *) buf1 + 17 - || memcmp (buf1, "RSTUVWXYZ01234567\0", 19)) - abort (); - - __builtin_memcpy (buf3, "aBcdEFghijklmnopq\0", 19); - - /* These should be handled either by movstrendM or mempcpy - call. */ - if (mempcpy ((char *) buf3 + 4, buf5, n + 6) != (char *) buf1 + 10 - || memcmp (buf1, "aBcdRSTUVWklmnopq\0", 19)) - abort (); - - if (__builtin_mempcpy ((char *) buf1 + ++i + 8, (char *) buf5 + 1, n + 1) - != (char *) buf1 + 12 - || memcmp (buf1, "aBcdRSTUVWkSmnopq\0", 19) - || i != 3) - abort (); - - if (mempcpy ((char *) buf3 + 14, buf6, n + 2) != (char *) buf1 + 16 - || memcmp (buf1, "aBcdRSTUVWkSmnrsq\0", 19)) - abort (); - - i = 1; - - /* These might be handled by store_by_pieces. */ - if (mempcpy (buf2, "ABCDEFGHI", 9) != buf2 + 9 - || memcmp (buf2, "ABCDEFGHI\0", 11)) - abort (); - - if (mempcpy (buf2, "abcdefghijklmnopq", 17) != buf2 + 17 - || memcmp (buf2, "abcdefghijklmnopq\0", 19)) - abort (); - - if (__builtin_mempcpy (buf4, "ABCDEF", 6) != buf2 + 6 - || memcmp (buf2, "ABCDEFghijklmnopq\0", 19)) - abort (); - - if (__builtin_mempcpy (buf4, "a", 1) != buf2 + 1 - || memcmp (buf2, "aBCDEFghijklmnopq\0", 19)) - abort (); - - if (mempcpy (buf4 + 2, "bcd" + i++, 2) != buf2 + 4 - || memcmp (buf2, "aBcdEFghijklmnopq\0", 19) - || i != 2) - abort (); - - /* These might be handled by move_by_pieces. */ - if (mempcpy (buf4 + 4, buf7, 6) != buf2 + 10 - || memcmp (buf2, "aBcdRSTUVWklmnopq\0", 19)) - abort (); - - if (__builtin_mempcpy (buf2 + i++ + 8, buf7 + 1, 1) - != buf2 + 11 - || memcmp (buf2, "aBcdRSTUVWSlmnopq\0", 19) - || i != 3) - abort (); - - if (mempcpy (buf4 + 14, buf6, 2) != buf2 + 16 - || memcmp (buf2, "aBcdRSTUVWSlmnrsq\0", 19)) - abort (); - - __builtin_memcpy (buf4, "aBcdEFghijklmnopq\0", 19); - - /* These should be handled either by movstrendM or mempcpy - call. */ - if (mempcpy (buf4 + 4, buf7, n + 6) != buf2 + 10 - || memcmp (buf2, "aBcdRSTUVWklmnopq\0", 19)) - abort (); - - if (__builtin_mempcpy (buf2 + i++ + 8, buf7 + 1, n + 1) - != buf2 + 12 - || memcmp (buf2, "aBcdRSTUVWkSmnopq\0", 19) - || i != 4) - abort (); - - 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 -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/string-8-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/string-8-lib.c deleted file mode 100644 index 9753c2498f1..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-8-lib.c +++ /dev/null @@ -1 +0,0 @@ -#include "lib/strlen.c" diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-8.c b/gcc/testsuite/gcc.c-torture/execute/builtins/string-8.c deleted file mode 100644 index 220b6ed8e2e..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-8.c +++ /dev/null @@ -1,41 +0,0 @@ -/* Copyright (C) 2003 Free Software Foundation. - - Test strlen optimizations on conditional expressions. - - Written by Jakub Jelinek, June 23, 2003. */ - -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; - -size_t -foo (void) -{ - if (l) - abort (); - return ++l; -} - -void -main_test (void) -{ - if (strlen (i ? "foo" + 1 : j ? "bar" + 1 : "baz" + 1) != 2) - abort (); - if (strlen (g++ ? "foo" : "bar") != 3 || g != 1) - abort (); - if (strlen (h++ ? "xfoo" + 1 : "bar") != 3 || h != 1) - abort (); - if (strlen ((i++, "baz")) != 3 || i != 1) - abort (); - /* The following calls might not optimize strlen call away. */ - inside_main = 0; - if (strlen (j ? "foo" + k++ : "bar" + k++) != 3 || k != 1) - abort (); - if (strlen (foo () ? "foo" : "bar") != 3 || l != 1) - abort (); -} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-9-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/string-9-lib.c deleted file mode 100644 index 0a0bbb8865a..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-9-lib.c +++ /dev/null @@ -1 +0,0 @@ -#include "lib/strcat.c" diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-9.c b/gcc/testsuite/gcc.c-torture/execute/builtins/string-9.c deleted file mode 100644 index ba70c397724..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-9.c +++ /dev/null @@ -1,79 +0,0 @@ -/* Copyright (C) 2000, 2003 Free Software Foundation. - - Ensure all expected transformations of builtin strcat occur and - perform correctly. - - Written by Kaveh R. Ghazi, 11/27/2000. */ - -extern int inside_main; -extern void abort (void); -typedef __SIZE_TYPE__ size_t; -extern char *strcat (char *, const char *); -extern char *strcpy (char *, const char *); -extern int strcmp (const char *, const char *); -extern void *memset (void *, int, size_t); -extern int memcmp (const void *, const void *, size_t); -#define RESET_DST_WITH(FILLER) \ - do { memset (dst, 'X', sizeof (dst)); strcpy (dst, (FILLER)); } while (0) - -void main_test (void) -{ - const char *const s1 = "hello world"; - const char *const s2 = ""; - char dst[64], *d2; - - RESET_DST_WITH (s1); - if (strcat (dst, "") != dst || strcmp (dst, s1)) - abort(); - RESET_DST_WITH (s1); - if (strcat (dst, s2) != dst || strcmp (dst, s1)) - abort(); - RESET_DST_WITH (s1); d2 = dst; - if (strcat (++d2, s2) != dst+1 || d2 != dst+1 || strcmp (dst, s1)) - abort(); - RESET_DST_WITH (s1); d2 = dst; - if (strcat (++d2+5, s2) != dst+6 || d2 != dst+1 || strcmp (dst, s1)) - abort(); - RESET_DST_WITH (s1); d2 = dst; - if (strcat (++d2+5, s1+11) != dst+6 || d2 != dst+1 || strcmp (dst, s1)) - abort(); - -#ifndef __OPTIMIZE_SIZE__ -# 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 - - RESET_DST_WITH (s1); - if (strcat (dst, " 1111") != dst - || memcmp (dst, "hello world 1111\0XXX", 20)) - abort(); - - RESET_DST_WITH (s1); - if (strcat (dst+5, " 2222") != dst+5 - || memcmp (dst, "hello world 2222\0XXX", 20)) - abort(); - - RESET_DST_WITH (s1); d2 = dst; - if (strcat (++d2+5, " 3333") != dst+6 || d2 != dst+1 - || memcmp (dst, "hello world 3333\0XXX", 20)) - abort(); - - RESET_DST_WITH (s1); - strcat (strcat (strcat (strcat (strcat (strcat (dst, ": this "), ""), - "is "), "a "), "test"), "."); - if (memcmp (dst, "hello world: this is a test.\0X", 30)) - abort(); - - /* Set inside_main again. */ - inside_main = 1; -#endif - - /* Test at least one instance of the __builtin_ style. We do this - to ensure that it works and that the prototype is correct. */ - RESET_DST_WITH (s1); - if (__builtin_strcat (dst, "") != dst || strcmp (dst, s1)) - abort(); -} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-asm-1-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/string-asm-1-lib.c deleted file mode 100644 index a0318212e67..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-asm-1-lib.c +++ /dev/null @@ -1,31 +0,0 @@ -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); -} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-asm-1.c b/gcc/testsuite/gcc.c-torture/execute/builtins/string-asm-1.c deleted file mode 100644 index 3c3e45dfa5d..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-asm-1.c +++ /dev/null @@ -1,45 +0,0 @@ -/* Copyright (C) 2000, 2003 Free Software Foundation. - - Ensure all expected transformations of builtin strstr occur and - perform correctly in presence of redirect. */ - -#define ASMNAME(cname) ASMNAME2 (__USER_LABEL_PREFIX__, cname) -#define ASMNAME2(prefix, cname) STRING (prefix) cname -#define STRING(x) #x - -typedef __SIZE_TYPE__ size_t; -extern void abort (void); -extern char *strstr (const char *, const char *) - __asm (ASMNAME ("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 (); -} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-asm-2-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/string-asm-2-lib.c deleted file mode 100644 index 16369a21794..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-asm-2-lib.c +++ /dev/null @@ -1,76 +0,0 @@ -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); -} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/string-asm-2.c b/gcc/testsuite/gcc.c-torture/execute/builtins/string-asm-2.c deleted file mode 100644 index e793778053a..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/builtins/string-asm-2.c +++ /dev/null @@ -1,47 +0,0 @@ -/* Copyright (C) 2003 Free Software Foundation. - - Test memcpy and memset in presence of redirect. */ - -#define ASMNAME(cname) ASMNAME2 (__USER_LABEL_PREFIX__, cname) -#define ASMNAME2(prefix, cname) STRING (prefix) cname -#define STRING(x) #x - -typedef __SIZE_TYPE__ size_t; -extern void abort (void); -extern void *memcpy (void *, const void *, size_t) - __asm (ASMNAME ("my_memcpy")); -extern void bcopy (const void *, void *, size_t) - __asm (ASMNAME ("my_bcopy")); -extern void *memset (void *, int, size_t) - __asm (ASMNAME ("my_memset")); -extern void bzero (void *, size_t) - __asm (ASMNAME ("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 (); -} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strlen-2-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strlen-2-lib.c new file mode 100644 index 00000000000..9753c2498f1 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strlen-2-lib.c @@ -0,0 +1 @@ +#include "lib/strlen.c" diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strlen-2.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strlen-2.c new file mode 100644 index 00000000000..29569b769a9 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strlen-2.c @@ -0,0 +1,40 @@ +/* Copyright (C) 2003 Free Software Foundation. + + Test strlen optimizations on conditional expressions. + + Written by Jakub Jelinek, June 23, 2003. */ + +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 int inside_main; + +size_t g, h, i, j, k, l; + +size_t +foo (void) +{ + if (l) + abort (); + return ++l; +} + +void +main_test (void) +{ + if (strlen (i ? "foo" + 1 : j ? "bar" + 1 : "baz" + 1) != 2) + abort (); + if (strlen (g++ ? "foo" : "bar") != 3 || g != 1) + abort (); + if (strlen (h++ ? "xfoo" + 1 : "bar") != 3 || h != 1) + abort (); + if (strlen ((i++, "baz")) != 3 || i != 1) + abort (); + /* The following calls might not optimize strlen call away. */ + inside_main = 0; + if (strlen (j ? "foo" + k++ : "bar" + k++) != 3 || k != 1) + abort (); + if (strlen (foo () ? "foo" : "bar") != 3 || l != 1) + abort (); +} 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 00000000000..9753c2498f1 --- /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 00000000000..cf77294713a --- /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 00000000000..1405a48f4bc --- /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/builtins/strncat.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strncat.c new file mode 100644 index 00000000000..2ef0e01aebc --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strncat.c @@ -0,0 +1,72 @@ +/* Copyright (C) 2000, 2003 Free Software Foundation. + + Ensure all expected transformations of builtin strncat occur and + perform correctly. + + Written by Kaveh R. Ghazi, 11/27/2000. */ + +extern void abort (void); +typedef __SIZE_TYPE__ size_t; +extern char *strncat (char *, const char *, size_t); +extern char *strcpy (char *, const char *); +extern int strcmp (const char *, const char *); +int x = 123; + +void +main_test (void) +{ + const char *const s1 = "hello world"; + const char *const s2 = ""; + char dst[64], *d2; + + strcpy (dst, s1); + if (strncat (dst, "", 100) != dst || strcmp (dst, s1)) + abort(); + strcpy (dst, s1); + if (strncat (dst, s2, 100) != dst || strcmp (dst, s1)) + abort(); + strcpy (dst, s1); d2 = dst; + if (strncat (++d2, s2, 100) != dst+1 || d2 != dst+1 || strcmp (dst, s1)) + abort(); + strcpy (dst, s1); d2 = dst; + if (strncat (++d2+5, s2, 100) != dst+6 || d2 != dst+1 || strcmp (dst, s1)) + abort(); + strcpy (dst, s1); d2 = dst; + if (strncat (++d2+5, s1+11, 100) != dst+6 || d2 != dst+1 || strcmp (dst, s1)) + abort(); + strcpy (dst, s1); d2 = dst; + if (strncat (++d2+5, s1, 0) != dst+6 || d2 != dst+1 || strcmp (dst, s1)) + abort(); + strcpy (dst, s1); d2 = dst; + if (strncat (++d2+5, "", ++x) != dst+6 || d2 != dst+1 || x != 124 + || strcmp (dst, s1)) + abort(); + + strcpy (dst, s1); + if (strncat (dst, "foo", 3) != dst || strcmp (dst, "hello worldfoo")) + abort(); + strcpy (dst, s1); + if (strncat (dst, "foo", 100) != dst || strcmp (dst, "hello worldfoo")) + abort(); + strcpy (dst, s1); + if (strncat (dst, s1, 100) != dst || strcmp (dst, "hello worldhello world")) + abort(); + strcpy (dst, s1); d2 = dst; + if (strncat (++d2, s1, 100) != dst+1 || d2 != dst+1 + || strcmp (dst, "hello worldhello world")) + abort(); + strcpy (dst, s1); d2 = dst; + if (strncat (++d2+5, s1, 100) != dst+6 || d2 != dst+1 + || strcmp (dst, "hello worldhello world")) + abort(); + strcpy (dst, s1); d2 = dst; + if (strncat (++d2+5, s1+5, 100) != dst+6 || d2 != dst+1 + || strcmp (dst, "hello world world")) + abort(); + + /* Test at least one instance of the __builtin_ style. We do this + to ensure that it works and that the prototype is correct. */ + strcpy (dst, s1); + if (__builtin_strncat (dst, "", 100) != dst || strcmp (dst, s1)) + abort(); +} 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 00000000000..266c4a49b4f --- /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/builtins/strncmp-2.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strncmp-2.c new file mode 100644 index 00000000000..c9d78783391 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strncmp-2.c @@ -0,0 +1,173 @@ +/* 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 !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. */ + s2 = s1; + if (strncmp (++s2, "ello", 3) != 0 || s2 != s1+1) + abort(); + s2 = s1; + if (strncmp ("ello", ++s2, 3) != 0 || s2 != s1+1) + abort(); + s2 = s1; + if (strncmp (++s2, "ello", 4) != 0 || s2 != s1+1) + abort(); + s2 = s1; + if (strncmp ("ello", ++s2, 4) != 0 || s2 != s1+1) + abort(); + s2 = s1; + if (strncmp (++s2, "ello", 5) <= 0 || s2 != s1+1) + abort(); + s2 = s1; + if (strncmp ("ello", ++s2, 5) >= 0 || s2 != s1+1) + abort(); + s2 = s1; + if (strncmp (++s2, "ello", 6) <= 0 || s2 != s1+1) + abort(); + s2 = s1; + if (strncmp ("ello", ++s2, 6) >= 0 || s2 != s1+1) + abort(); + + s2 = s1; + if (strncmp (++s2, "zllo", 3) >= 0 || s2 != s1+1) + abort(); + s2 = s1; + if (strncmp ("zllo", ++s2, 3) <= 0 || s2 != s1+1) + abort(); + s2 = s1; + if (strncmp (++s2, "zllo", 4) >= 0 || s2 != s1+1) + abort(); + s2 = s1; + if (strncmp ("zllo", ++s2, 4) <= 0 || s2 != s1+1) + abort(); + s2 = s1; + if (strncmp (++s2, "zllo", 5) >= 0 || s2 != s1+1) + abort(); + s2 = s1; + if (strncmp ("zllo", ++s2, 5) <= 0 || s2 != s1+1) + abort(); + s2 = s1; + if (strncmp (++s2, "zllo", 6) >= 0 || s2 != s1+1) + abort(); + s2 = s1; + if (strncmp ("zllo", ++s2, 6) <= 0 || s2 != s1+1) + abort(); + + s2 = s1; + if (strncmp (++s2, "allo", 3) <= 0 || s2 != s1+1) + abort(); + s2 = s1; + if (strncmp ("allo", ++s2, 3) >= 0 || s2 != s1+1) + abort(); + s2 = s1; + if (strncmp (++s2, "allo", 4) <= 0 || s2 != s1+1) + abort(); + s2 = s1; + if (strncmp ("allo", ++s2, 4) >= 0 || s2 != s1+1) + abort(); + s2 = s1; + if (strncmp (++s2, "allo", 5) <= 0 || s2 != s1+1) + abort(); + s2 = s1; + if (strncmp ("allo", ++s2, 5) >= 0 || s2 != s1+1) + abort(); + s2 = s1; + if (strncmp (++s2, "allo", 6) <= 0 || s2 != s1+1) + abort(); + s2 = s1; + if (strncmp ("allo", ++s2, 6) >= 0 || s2 != s1+1) + abort(); + + s2 = s1; n = 2; x = 1; + if (strncmp (++s2, s1+(x&3), ++n) != 0 || s2 != s1+1 || n != 3) + abort(); + s2 = s1; n = 2; x = 1; + if (strncmp (s1+(x&3), ++s2, ++n) != 0 || s2 != s1+1 || n != 3) + abort(); + s2 = s1; n = 3; x = 1; + if (strncmp (++s2, s1+(x&3), ++n) != 0 || s2 != s1+1 || n != 4) + abort(); + s2 = s1; n = 3; x = 1; + if (strncmp (s1+(x&3), ++s2, ++n) != 0 || s2 != s1+1 || n != 4) + abort(); + s2 = s1; n = 4; x = 1; + if (strncmp (++s2, s1+(x&3), ++n) != 0 || s2 != s1+1 || n != 5) + abort(); + s2 = s1; n = 4; x = 1; + if (strncmp (s1+(x&3), ++s2, ++n) != 0 || s2 != s1+1 || n != 5) + abort(); + s2 = s1; n = 5; x = 1; + if (strncmp (++s2, s1+(x&3), ++n) != 0 || s2 != s1+1 || n != 6) + abort(); + s2 = s1; n = 5; x = 1; + if (strncmp (s1+(x&3), ++s2, ++n) != 0 || s2 != s1+1 || n != 6) + abort(); + + s2 = s1; n = 2; + if (strncmp (++s2, "zllo", ++n) >= 0 || s2 != s1+1 || n != 3) + abort(); + s2 = s1; n = 2; x = 1; + if (strncmp ("zllo", ++s2, ++n) <= 0 || s2 != s1+1 || n != 3) + abort(); + s2 = s1; n = 3; x = 1; + if (strncmp (++s2, "zllo", ++n) >= 0 || s2 != s1+1 || n != 4) + abort(); + s2 = s1; n = 3; x = 1; + if (strncmp ("zllo", ++s2, ++n) <= 0 || s2 != s1+1 || n != 4) + abort(); + s2 = s1; n = 4; x = 1; + if (strncmp (++s2, "zllo", ++n) >= 0 || s2 != s1+1 || n != 5) + abort(); + s2 = s1; n = 4; x = 1; + if (strncmp ("zllo", ++s2, ++n) <= 0 || s2 != s1+1 || n != 5) + abort(); + s2 = s1; n = 5; x = 1; + if (strncmp (++s2, "zllo", ++n) >= 0 || s2 != s1+1 || n != 6) + abort(); + s2 = s1; n = 5; x = 1; + if (strncmp ("zllo", ++s2, ++n) <= 0 || s2 != s1+1 || n != 6) + abort(); + + s2 = s1; n = 2; + if (strncmp (++s2, "allo", ++n) <= 0 || s2 != s1+1 || n != 3) + abort(); + s2 = s1; n = 2; x = 1; + if (strncmp ("allo", ++s2, ++n) >= 0 || s2 != s1+1 || n != 3) + abort(); + s2 = s1; n = 3; x = 1; + if (strncmp (++s2, "allo", ++n) <= 0 || s2 != s1+1 || n != 4) + abort(); + s2 = s1; n = 3; x = 1; + if (strncmp ("allo", ++s2, ++n) >= 0 || s2 != s1+1 || n != 4) + abort(); + s2 = s1; n = 4; x = 1; + if (strncmp (++s2, "allo", ++n) <= 0 || s2 != s1+1 || n != 5) + abort(); + s2 = s1; n = 4; x = 1; + if (strncmp ("allo", ++s2, ++n) >= 0 || s2 != s1+1 || n != 5) + abort(); + s2 = s1; n = 5; x = 1; + if (strncmp (++s2, "allo", ++n) <= 0 || s2 != s1+1 || n != 6) + abort(); + s2 = s1; n = 5; x = 1; + if (strncmp ("allo", ++s2, ++n) >= 0 || s2 != s1+1 || n != 6) + 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 00000000000..266c4a49b4f --- /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 00000000000..888faf569e7 --- /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 00000000000..784f72d0335 --- /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/builtins/strncpy.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strncpy.c new file mode 100644 index 00000000000..c0a815701e6 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strncpy.c @@ -0,0 +1,75 @@ +/* Copyright (C) 2000 Free Software Foundation. + + Ensure all expected transformations of builtin strncpy occur and + perform correctly. + + Written by Kaveh R. Ghazi, 11/25/2000. */ + +extern void abort (void); +typedef __SIZE_TYPE__ size_t; +extern char *strncpy (char *, const char *, size_t); +extern int strcmp (const char *, const char *); +extern int strncmp (const char *, const char *, size_t); +extern void *memset (void *, int, size_t); + +int i; + +void +main_test (void) +{ + const char *const src = "hello world"; + const char *src2; + char dst[64], *dst2; + + memset (dst, 0, sizeof (dst)); + if (strncpy (dst, src, 4) != dst || strncmp (dst, src, 4)) + abort(); + + memset (dst, 0, sizeof (dst)); + if (strncpy (dst+16, src, 4) != dst+16 || strncmp (dst+16, src, 4)) + abort(); + + memset (dst, 0, sizeof (dst)); + if (strncpy (dst+32, src+5, 4) != dst+32 || strncmp (dst+32, src+5, 4)) + abort(); + + memset (dst, 0, sizeof (dst)); + dst2 = dst; + if (strncpy (++dst2, src+5, 4) != dst+1 || strncmp (dst2, src+5, 4) + || dst2 != dst+1) + abort(); + + memset (dst, 0, sizeof (dst)); + if (strncpy (dst, src, 0) != dst || strcmp (dst, "")) + abort(); + + memset (dst, 0, sizeof (dst)); + dst2 = dst; src2 = src; + if (strncpy (++dst2, ++src2, 0) != dst+1 || strcmp (dst2, "") + || dst2 != dst+1 || src2 != src+1) + abort(); + + memset (dst, 0, sizeof (dst)); + dst2 = dst; src2 = src; + if (strncpy (++dst2+5, ++src2+5, 0) != dst+6 || strcmp (dst2+5, "") + || dst2 != dst+1 || src2 != src+1) + abort(); + + memset (dst, 0, sizeof (dst)); + if (strncpy (dst, src, 12) != dst || strcmp (dst, src)) + abort(); + + /* Test at least one instance of the __builtin_ style. We do this + to ensure that it works and that the prototype is correct. */ + memset (dst, 0, sizeof (dst)); + if (__builtin_strncpy (dst, src, 4) != dst || strncmp (dst, src, 4)) + abort(); + + memset (dst, 0, sizeof (dst)); + if (strncpy (dst, i++ ? "xfoo" + 1 : "bar", 4) != dst + || strcmp (dst, "bar") + || i != 1) + abort (); + + return 0; +} 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 00000000000..66bf8be7c84 --- /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/builtins/strpbrk.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strpbrk.c new file mode 100644 index 00000000000..cc963a9af5e --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strpbrk.c @@ -0,0 +1,42 @@ +/* Copyright (C) 2000 Free Software Foundation. + + Ensure all expected transformations of builtin strpbrk occur and + perform correctly. + + Written by Kaveh R. Ghazi, 11/6/2000. */ + +extern void abort(void); +extern char *strpbrk (const char *, const char *); +extern int strcmp (const char *, const char *); + +void fn (const char *foo, const char *const *bar) +{ + if (strcmp(strpbrk ("hello world", "lrooo"), "llo world") != 0) + abort(); + if (strpbrk (foo, "") != 0) + abort(); + if (strpbrk (foo + 4, "") != 0) + abort(); + if (strpbrk (*bar--, "") != 0) + abort(); + if (strpbrk (*bar, "h") != foo) + abort(); + if (strpbrk (foo, "h") != foo) + abort(); + if (strpbrk (foo, "w") != foo + 6) + abort(); + if (strpbrk (foo + 6, "o") != foo + 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_strpbrk (foo + 6, "o") != foo + 7) + abort(); +} + +void +main_test (void) +{ + const char *const foo[] = { "hello world", "bye bye world" }; + fn (foo[0], foo + 1); +} 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 00000000000..b31cdf4f594 --- /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 00000000000..eb275c422c2 --- /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 00000000000..b31cdf4f594 --- /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 00000000000..737bfaa805a --- /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 00000000000..90475eca33d --- /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 00000000000..3cc8faa2e23 --- /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 00000000000..9e044d793e1 --- /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/builtins/strspn.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strspn.c new file mode 100644 index 00000000000..4f2782a58b6 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strspn.c @@ -0,0 +1,54 @@ +/* Copyright (C) 2000 Free Software Foundation. + + Ensure all expected transformations of builtin strspn occur and + perform correctly. + + Written by Kaveh R. Ghazi, 11/27/2000. */ + +extern void abort (void); +typedef __SIZE_TYPE__ size_t; +extern size_t strspn (const char *, const char *); +extern char *strcpy (char *, const char *); + +void +main_test (void) +{ + const char *const s1 = "hello world"; + char dst[64], *d2; + + if (strspn (s1, "hello") != 5) + abort(); + if (strspn (s1+4, "hello") != 1) + abort(); + if (strspn (s1, "z") != 0) + abort(); + if (strspn (s1, "hello world") != 11) + abort(); + if (strspn (s1, "") != 0) + abort(); + strcpy (dst, s1); + if (strspn (dst, "") != 0) + abort(); + strcpy (dst, s1); d2 = dst; + if (strspn (++d2, "") != 0 || d2 != dst+1) + abort(); + strcpy (dst, s1); d2 = dst; + if (strspn (++d2+5, "") != 0 || d2 != dst+1) + abort(); + if (strspn ("", s1) != 0) + abort(); + strcpy (dst, s1); + if (strspn ("", dst) != 0) + abort(); + strcpy (dst, s1); d2 = dst; + if (strspn ("", ++d2) != 0 || d2 != dst+1) + abort(); + strcpy (dst, s1); d2 = dst; + if (strspn ("", ++d2+5) != 0 || d2 != dst+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_strspn (s1, "hello") != 5) + abort(); +} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strstr-asm-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strstr-asm-lib.c new file mode 100644 index 00000000000..a0318212e67 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strstr-asm-lib.c @@ -0,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); +} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strstr-asm.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strstr-asm.c new file mode 100644 index 00000000000..3c3e45dfa5d --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strstr-asm.c @@ -0,0 +1,45 @@ +/* Copyright (C) 2000, 2003 Free Software Foundation. + + Ensure all expected transformations of builtin strstr occur and + perform correctly in presence of redirect. */ + +#define ASMNAME(cname) ASMNAME2 (__USER_LABEL_PREFIX__, cname) +#define ASMNAME2(prefix, cname) STRING (prefix) cname +#define STRING(x) #x + +typedef __SIZE_TYPE__ size_t; +extern void abort (void); +extern char *strstr (const char *, const char *) + __asm (ASMNAME ("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 (); +} 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 00000000000..591058de499 --- /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/builtins/strstr.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strstr.c new file mode 100644 index 00000000000..ae503aa43e0 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strstr.c @@ -0,0 +1,33 @@ +/* Copyright (C) 2000 Free Software Foundation. + + Ensure all expected transformations of builtin strstr occur and + perform correctly. + + Written by Kaveh R. Ghazi, 11/6/2000. */ + +extern void abort(void); +extern char *strstr (const char *, const char *); + +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(); + + /* 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(); +} diff --git a/gcc/testsuite/gcc.c-torture/execute/stdio-opt-1.c b/gcc/testsuite/gcc.c-torture/execute/stdio-opt-1.c deleted file mode 100644 index 8cfb4ebe08e..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/stdio-opt-1.c +++ /dev/null @@ -1,78 +0,0 @@ -/* Copyright (C) 2000, 2001 Free Software Foundation. - - Ensure all expected transformations of builtin fputs occur and that - we honor side effects in the stream argument. - - Written by Kaveh R. Ghazi, 10/30/2000. */ - -#include -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() -{ - FILE *s_array[] = {stdout, NULL}, **s_ptr = s_array; - const char *const s1 = "hello world"; - - fputs ("", *s_ptr); - fputs ("\n", *s_ptr); - fputs ("bye", *s_ptr); - fputs (s1, *s_ptr); - fputs (s1+5, *s_ptr); - fputs (s1+10, *s_ptr); - fputs (s1+11, *s_ptr); - - /* Check side-effects when transforming fputs -> NOP. */ - fputs ("", *s_ptr++); - if (s_ptr != s_array+1 || *s_ptr != 0) - abort(); - - /* Check side-effects when transforming fputs -> fputc. */ - s_ptr = s_array; - fputs ("\n", *s_ptr++); - if (s_ptr != s_array+1 || *s_ptr != 0) - abort(); - - /* Check side-effects when transforming fputs -> fwrite. */ - s_ptr = s_array; - fputs ("hello\n", *s_ptr++); - if (s_ptr != s_array+1 || *s_ptr != 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. */ - s_ptr = s_array; - __builtin_fputs ("", *s_ptr); - /* These builtin stubs are called by __builtin_fputs, ensure their - prototypes are set correctly too. */ - __builtin_fputc ('\n', *s_ptr); - __builtin_fwrite ("hello\n", 1, 6, *s_ptr); - - /* Check side-effects in conditional expression. */ - s_ptr = s_array; - fputs (i++ ? "f" : "x", *s_ptr++); - if (s_ptr != s_array+1 || *s_ptr != 0 || i != 1) - abort(); - 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/stdio-opt-2.c b/gcc/testsuite/gcc.c-torture/execute/stdio-opt-2.c deleted file mode 100644 index 833017ee547..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/stdio-opt-2.c +++ /dev/null @@ -1,54 +0,0 @@ -/* Copyright (C) 2000 Free Software Foundation. - - Ensure all expected transformations of builtin printf occur and - that we honor side effects in the arguments. - - Written by Kaveh R. Ghazi, 12/4/2000. */ - -extern int printf (const char *, ...); -extern void abort(void); - -int main() -{ - const char *const s1 = "hello world"; - const char *const s2[] = { s1, 0 }, *const*s3; - - printf ("%s\n", "hello"); - printf ("%s\n", *s2); - s3 = s2; - printf ("%s\n", *s3++); - if (s3 != s2+1 || *s3 != 0) - abort(); - - printf ("%c", '\n'); - printf ("%c", **s2); - s3 = s2; - printf ("%c", **s3++); - if (s3 != s2+1 || *s3 != 0) - abort(); - - printf ("\n"); - printf ("hello world\n"); - - /* Test at least one instance of the __builtin_ style. We do this - to ensure that it works and that the prototype is correct. */ - __builtin_printf ("%s\n", "hello"); - /* These builtin stubs are called by __builtin_printf, ensure their - 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/stdio-opt-3.c b/gcc/testsuite/gcc.c-torture/execute/stdio-opt-3.c deleted file mode 100644 index afc76a21716..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/stdio-opt-3.c +++ /dev/null @@ -1,66 +0,0 @@ -/* Copyright (C) 2001 Free Software Foundation. - - Ensure all expected transformations of builtin fprintf occur and - that we honor side effects in the arguments. - - Written by Kaveh R. Ghazi, 1/7/2001. */ - -#include -extern int fprintf (FILE *, const char *, ...); -extern void abort(void); - -int main() -{ - FILE *s_array[] = {stdout, NULL}, **s_ptr = s_array; - const char *const s1 = "hello world"; - const char *const s2[] = { s1, 0 }, *const*s3; - - fprintf (*s_ptr, "%s", "hello"); - fprintf (*s_ptr, "%s", "\n"); - fprintf (*s_ptr, "%s", *s2); - s3 = s2; - fprintf (*s_ptr, "%s", *s3++); - if (s3 != s2+1 || *s3 != 0) - abort(); - s3 = s2; - fprintf (*s_ptr++, "%s", *s3++); - if (s3 != s2+1 || *s3 != 0 || s_ptr != s_array+1 || *s_ptr != 0) - abort(); - - s_ptr = s_array; - fprintf (*s_ptr, "%c", '\n'); - fprintf (*s_ptr, "%c", **s2); - s3 = s2; - fprintf (*s_ptr, "%c", **s3++); - if (s3 != s2+1 || *s3 != 0) - abort(); - s3 = s2; - fprintf (*s_ptr++, "%c", **s3++); - if (s3 != s2+1 || *s3 != 0 || s_ptr != s_array+1 || *s_ptr != 0) - abort(); - - s_ptr = s_array; - fprintf (*s_ptr++, "hello world"); - if (s_ptr != s_array+1 || *s_ptr != 0) - abort(); - s_ptr = s_array; - fprintf (*s_ptr, "\n"); - - /* 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/string-opt-1.c b/gcc/testsuite/gcc.c-torture/execute/string-opt-1.c deleted file mode 100644 index 6b59c10f29b..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/string-opt-1.c +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright (C) 2000 Free Software Foundation. - - Ensure all expected transformations of builtin strstr occur and - perform correctly. - - Written by Kaveh R. Ghazi, 11/6/2000. */ - -extern void abort(void); -extern char *strstr (const char *, const char *); - -int main() -{ - 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(); - - /* 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(); - - 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-10.c b/gcc/testsuite/gcc.c-torture/execute/string-opt-10.c deleted file mode 100644 index b883dd61e01..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/string-opt-10.c +++ /dev/null @@ -1,85 +0,0 @@ -/* Copyright (C) 2000, 2003 Free Software Foundation. - - Ensure all expected transformations of builtin strncat occur and - perform correctly. - - Written by Kaveh R. Ghazi, 11/27/2000. */ - -extern void abort (void); -typedef __SIZE_TYPE__ size_t; -extern char *strncat (char *, const char *, size_t); -extern char *strcpy (char *, const char *); -extern int strcmp (const char *, const char *); -int x = 123; - -int main () -{ - const char *const s1 = "hello world"; - const char *const s2 = ""; - char dst[64], *d2; - - strcpy (dst, s1); - if (strncat (dst, "", 100) != dst || strcmp (dst, s1)) - abort(); - strcpy (dst, s1); - if (strncat (dst, s2, 100) != dst || strcmp (dst, s1)) - abort(); - strcpy (dst, s1); d2 = dst; - if (strncat (++d2, s2, 100) != dst+1 || d2 != dst+1 || strcmp (dst, s1)) - abort(); - strcpy (dst, s1); d2 = dst; - if (strncat (++d2+5, s2, 100) != dst+6 || d2 != dst+1 || strcmp (dst, s1)) - abort(); - strcpy (dst, s1); d2 = dst; - if (strncat (++d2+5, s1+11, 100) != dst+6 || d2 != dst+1 || strcmp (dst, s1)) - abort(); - strcpy (dst, s1); d2 = dst; - if (strncat (++d2+5, s1, 0) != dst+6 || d2 != dst+1 || strcmp (dst, s1)) - abort(); - strcpy (dst, s1); d2 = dst; - if (strncat (++d2+5, "", ++x) != dst+6 || d2 != dst+1 || x != 124 - || strcmp (dst, s1)) - abort(); - - strcpy (dst, s1); - if (strncat (dst, "foo", 3) != dst || strcmp (dst, "hello worldfoo")) - abort(); - strcpy (dst, s1); - if (strncat (dst, "foo", 100) != dst || strcmp (dst, "hello worldfoo")) - abort(); - strcpy (dst, s1); - if (strncat (dst, s1, 100) != dst || strcmp (dst, "hello worldhello world")) - abort(); - strcpy (dst, s1); d2 = dst; - if (strncat (++d2, s1, 100) != dst+1 || d2 != dst+1 - || strcmp (dst, "hello worldhello world")) - abort(); - strcpy (dst, s1); d2 = dst; - if (strncat (++d2+5, s1, 100) != dst+6 || d2 != dst+1 - || strcmp (dst, "hello worldhello world")) - abort(); - strcpy (dst, s1); d2 = dst; - if (strncat (++d2+5, s1+5, 100) != dst+6 || d2 != dst+1 - || strcmp (dst, "hello world world")) - abort(); - - /* Test at least one instance of the __builtin_ style. We do this - to ensure that it works and that the prototype is correct. */ - 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/string-opt-11.c b/gcc/testsuite/gcc.c-torture/execute/string-opt-11.c deleted file mode 100644 index 0aa186299df..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/string-opt-11.c +++ /dev/null @@ -1,67 +0,0 @@ -/* Copyright (C) 2000 Free Software Foundation. - - Ensure all expected transformations of builtin strspn occur and - perform correctly. - - Written by Kaveh R. Ghazi, 11/27/2000. */ - -extern void abort (void); -typedef __SIZE_TYPE__ size_t; -extern size_t strspn (const char *, const char *); -extern char *strcpy (char *, const char *); - -int main () -{ - const char *const s1 = "hello world"; - char dst[64], *d2; - - if (strspn (s1, "hello") != 5) - abort(); - if (strspn (s1+4, "hello") != 1) - abort(); - if (strspn (s1, "z") != 0) - abort(); - if (strspn (s1, "hello world") != 11) - abort(); - if (strspn (s1, "") != 0) - abort(); - strcpy (dst, s1); - if (strspn (dst, "") != 0) - abort(); - strcpy (dst, s1); d2 = dst; - if (strspn (++d2, "") != 0 || d2 != dst+1) - abort(); - strcpy (dst, s1); d2 = dst; - if (strspn (++d2+5, "") != 0 || d2 != dst+1) - abort(); - if (strspn ("", s1) != 0) - abort(); - strcpy (dst, s1); - if (strspn ("", dst) != 0) - abort(); - strcpy (dst, s1); d2 = dst; - if (strspn ("", ++d2) != 0 || d2 != dst+1) - abort(); - strcpy (dst, s1); d2 = dst; - if (strspn ("", ++d2+5) != 0 || d2 != dst+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_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/string-opt-12.c b/gcc/testsuite/gcc.c-torture/execute/string-opt-12.c deleted file mode 100644 index 1d20f1e6708..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/string-opt-12.c +++ /dev/null @@ -1,67 +0,0 @@ -/* Copyright (C) 2000 Free Software Foundation. - - Ensure all expected transformations of builtin strcspn occur and - perform correctly. - - Written by Kaveh R. Ghazi, 11/27/2000. */ - -extern void abort (void); -typedef __SIZE_TYPE__ size_t; -extern size_t strcspn (const char *, const char *); -extern char *strcpy (char *, const char *); - -int main () -{ - const char *const s1 = "hello world"; - char dst[64], *d2; - - if (strcspn (s1, "hello") != 0) - abort(); - if (strcspn (s1, "z") != 11) - abort(); - if (strcspn (s1+4, "z") != 7) - abort(); - if (strcspn (s1, "hello world") != 0) - abort(); - if (strcspn (s1, "") != 11) - abort(); - strcpy (dst, s1); - if (strcspn (dst, "") != 11) - abort(); - strcpy (dst, s1); d2 = dst; - if (strcspn (++d2, "") != 10 || d2 != dst+1) - abort(); - strcpy (dst, s1); d2 = dst; - if (strcspn (++d2+5, "") != 5 || d2 != dst+1) - abort(); - if (strcspn ("", s1) != 0) - abort(); - strcpy (dst, s1); - if (strcspn ("", dst) != 0) - abort(); - strcpy (dst, s1); d2 = dst; - if (strcspn ("", ++d2) != 0 || d2 != dst+1) - abort(); - strcpy (dst, s1); d2 = dst; - if (strcspn ("", ++d2+5) != 0 || d2 != dst+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_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/string-opt-13.c b/gcc/testsuite/gcc.c-torture/execute/string-opt-13.c deleted file mode 100644 index 9d79ef0d817..00000000000 --- 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 cb0bfcb9dff..00000000000 --- 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 - diff --git a/gcc/testsuite/gcc.c-torture/execute/string-opt-15.c b/gcc/testsuite/gcc.c-torture/execute/string-opt-15.c deleted file mode 100644 index e2395d4dfeb..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/string-opt-15.c +++ /dev/null @@ -1,47 +0,0 @@ -/* Copyright (C) 2001 Free Software Foundation. - - Ensure that short builtin memcmp are optimized and perform correctly. - 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. */ - -extern void abort (void); -typedef __SIZE_TYPE__ size_t; -extern int memcmp (const void *, const void *, size_t); -extern char *strcpy (char *, const char *); - -int -main () -{ - char str[8]; - - strcpy (str, "3141"); - - if ( memcmp (str, str+2, 0) != 0 ) - abort (); - if ( memcmp (str+1, str+3, 0) != 0 ) - abort (); - - if ( memcmp (str+1, str+3, 1) != 0 ) - abort (); - if ( memcmp (str, str+2, 1) >= 0 ) - abort (); - if ( memcmp (str+2, str, 1) <= 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 -memcmp (const void *p1, const void *p2, size_t len) -{ - abort (); -} -#endif - diff --git a/gcc/testsuite/gcc.c-torture/execute/string-opt-16.c b/gcc/testsuite/gcc.c-torture/execute/string-opt-16.c deleted file mode 100644 index 8556b8f6517..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/string-opt-16.c +++ /dev/null @@ -1,85 +0,0 @@ -/* Copyright (C) 2003 Free Software Foundation. - - Test sprintf optimizations don't break anything and return the - correct results. - - Written by Roger Sayle, June 22, 2003. */ - -static char buffer[32]; - -extern void abort (); -typedef __SIZE_TYPE__ size_t; -extern int sprintf(char*, const char*, ...); -extern void *memset(void*, int, size_t); -extern int memcmp(const void*, const void*, size_t); - -void test1() -{ - sprintf(buffer,"foo"); -} - -int test2() -{ - return sprintf(buffer,"foo"); -} - -void test3() -{ - sprintf(buffer,"%s","bar"); -} - -int test4() -{ - return sprintf(buffer,"%s","bar"); -} - -void test5(char *ptr) -{ - sprintf(buffer,"%s",ptr); -} - - -int main() -{ - memset (buffer, 'A', 32); - test1 (); - if (memcmp(buffer, "foo", 4) || buffer[4] != 'A') - abort (); - - memset (buffer, 'A', 32); - if (test2 () != 3) - abort (); - if (memcmp(buffer, "foo", 4) || buffer[4] != 'A') - abort (); - - memset (buffer, 'A', 32); - test3 (); - if (memcmp(buffer, "bar", 4) || buffer[4] != 'A') - abort (); - - memset (buffer, 'A', 32); - if (test4 () != 3) - abort (); - if (memcmp(buffer, "bar", 4) || buffer[4] != 'A') - abort (); - - memset (buffer, 'A', 32); - 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/string-opt-2.c b/gcc/testsuite/gcc.c-torture/execute/string-opt-2.c deleted file mode 100644 index d8ebb77be51..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/string-opt-2.c +++ /dev/null @@ -1,55 +0,0 @@ -/* Copyright (C) 2000 Free Software Foundation. - - Ensure all expected transformations of builtin strpbrk occur and - perform correctly. - - Written by Kaveh R. Ghazi, 11/6/2000. */ - -extern void abort(void); -extern char *strpbrk (const char *, const char *); -extern int strcmp (const char *, const char *); - -void fn (const char *foo, const char *const *bar) -{ - if (strcmp(strpbrk ("hello world", "lrooo"), "llo world") != 0) - abort(); - if (strpbrk (foo, "") != 0) - abort(); - if (strpbrk (foo + 4, "") != 0) - abort(); - if (strpbrk (*bar--, "") != 0) - abort(); - if (strpbrk (*bar, "h") != foo) - abort(); - if (strpbrk (foo, "h") != foo) - abort(); - if (strpbrk (foo, "w") != foo + 6) - abort(); - if (strpbrk (foo + 6, "o") != foo + 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_strpbrk (foo + 6, "o") != foo + 7) - abort(); -} - -int main() -{ - 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/string-opt-6.c b/gcc/testsuite/gcc.c-torture/execute/string-opt-6.c deleted file mode 100644 index c684dbd4f13..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/string-opt-6.c +++ /dev/null @@ -1,54 +0,0 @@ -/* Copyright (C) 2000 Free Software Foundation. - - Ensure builtin memcpy and strcpy perform correctly. - - Written by Jakub Jelinek, 11/24/2000. */ - -extern void abort (void); -extern char *strcpy (char *, const char *); -typedef __SIZE_TYPE__ size_t; -extern void *memcpy (void *, const void *, size_t); -extern int memcmp (const void *, const void *, size_t); - -char p[32] = ""; - -int main() -{ - if (strcpy (p, "abcde") != p || memcmp (p, "abcde", 6)) - abort (); - if (strcpy (p + 16, "vwxyz" + 1) != p + 16 || memcmp (p + 16, "wxyz", 5)) - abort (); - if (strcpy (p + 1, "") != p + 1 || memcmp (p, "a\0cde", 6)) - abort (); - if (strcpy (p + 3, "fghij") != p + 3 || memcmp (p, "a\0cfghij", 9)) - abort (); - if (memcpy (p, "ABCDE", 6) != p || memcmp (p, "ABCDE", 6)) - abort (); - if (memcpy (p + 16, "VWX" + 1, 2) != p + 16 || memcmp (p + 16, "WXyz", 5)) - abort (); - if (memcpy (p + 1, "", 1) != p + 1 || memcmp (p, "A\0CDE", 6)) - abort (); - if (memcpy (p + 3, "FGHI", 4) != p + 3 || memcmp (p, "A\0CFGHIj", 9)) - 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_strcpy (p, "abcde") != p || memcmp (p, "abcde", 6)) - 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/string-opt-7.c b/gcc/testsuite/gcc.c-torture/execute/string-opt-7.c deleted file mode 100644 index 5b915d7a7d3..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/string-opt-7.c +++ /dev/null @@ -1,86 +0,0 @@ -/* Copyright (C) 2000 Free Software Foundation. - - Ensure all expected transformations of builtin strncpy occur and - perform correctly. - - Written by Kaveh R. Ghazi, 11/25/2000. */ - -extern void abort (void); -typedef __SIZE_TYPE__ size_t; -extern char *strncpy (char *, const char *, size_t); -extern int strcmp (const char *, const char *); -extern int strncmp (const char *, const char *, size_t); -extern void *memset (void *, int, size_t); - -int i; - -int main () -{ - const char *const src = "hello world"; - const char *src2; - char dst[64], *dst2; - - memset (dst, 0, sizeof (dst)); - if (strncpy (dst, src, 4) != dst || strncmp (dst, src, 4)) - abort(); - - memset (dst, 0, sizeof (dst)); - if (strncpy (dst+16, src, 4) != dst+16 || strncmp (dst+16, src, 4)) - abort(); - - memset (dst, 0, sizeof (dst)); - if (strncpy (dst+32, src+5, 4) != dst+32 || strncmp (dst+32, src+5, 4)) - abort(); - - memset (dst, 0, sizeof (dst)); - dst2 = dst; - if (strncpy (++dst2, src+5, 4) != dst+1 || strncmp (dst2, src+5, 4) - || dst2 != dst+1) - abort(); - - memset (dst, 0, sizeof (dst)); - if (strncpy (dst, src, 0) != dst || strcmp (dst, "")) - abort(); - - memset (dst, 0, sizeof (dst)); - dst2 = dst; src2 = src; - if (strncpy (++dst2, ++src2, 0) != dst+1 || strcmp (dst2, "") - || dst2 != dst+1 || src2 != src+1) - abort(); - - memset (dst, 0, sizeof (dst)); - dst2 = dst; src2 = src; - if (strncpy (++dst2+5, ++src2+5, 0) != dst+6 || strcmp (dst2+5, "") - || dst2 != dst+1 || src2 != src+1) - abort(); - - memset (dst, 0, sizeof (dst)); - if (strncpy (dst, src, 12) != dst || strcmp (dst, src)) - abort(); - - /* Test at least one instance of the __builtin_ style. We do this - to ensure that it works and that the prototype is correct. */ - memset (dst, 0, sizeof (dst)); - if (__builtin_strncpy (dst, src, 4) != dst || strncmp (dst, src, 4)) - abort(); - - memset (dst, 0, sizeof (dst)); - if (strncpy (dst, i++ ? "xfoo" + 1 : "bar", 4) != dst - || strcmp (dst, "bar") - || i != 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 char * -strncpy(char *s1, const char *s2, size_t n) -{ - abort(); -} -#endif diff --git a/gcc/testsuite/gcc.c-torture/execute/string-opt-8.c b/gcc/testsuite/gcc.c-torture/execute/string-opt-8.c deleted file mode 100644 index 2316fce87ca..00000000000 --- a/gcc/testsuite/gcc.c-torture/execute/string-opt-8.c +++ /dev/null @@ -1,241 +0,0 @@ -/* 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); - -int main () -{ - 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. */ - s2 = s1; - if (strncmp (++s2, "ello", 3) != 0 || s2 != s1+1) - abort(); - s2 = s1; - if (strncmp ("ello", ++s2, 3) != 0 || s2 != s1+1) - abort(); - s2 = s1; - if (strncmp (++s2, "ello", 4) != 0 || s2 != s1+1) - abort(); - s2 = s1; - if (strncmp ("ello", ++s2, 4) != 0 || s2 != s1+1) - abort(); - s2 = s1; - if (strncmp (++s2, "ello", 5) <= 0 || s2 != s1+1) - abort(); - s2 = s1; - if (strncmp ("ello", ++s2, 5) >= 0 || s2 != s1+1) - abort(); - s2 = s1; - if (strncmp (++s2, "ello", 6) <= 0 || s2 != s1+1) - abort(); - s2 = s1; - if (strncmp ("ello", ++s2, 6) >= 0 || s2 != s1+1) - abort(); - - s2 = s1; - if (strncmp (++s2, "zllo", 3) >= 0 || s2 != s1+1) - abort(); - s2 = s1; - if (strncmp ("zllo", ++s2, 3) <= 0 || s2 != s1+1) - abort(); - s2 = s1; - if (strncmp (++s2, "zllo", 4) >= 0 || s2 != s1+1) - abort(); - s2 = s1; - if (strncmp ("zllo", ++s2, 4) <= 0 || s2 != s1+1) - abort(); - s2 = s1; - if (strncmp (++s2, "zllo", 5) >= 0 || s2 != s1+1) - abort(); - s2 = s1; - if (strncmp ("zllo", ++s2, 5) <= 0 || s2 != s1+1) - abort(); - s2 = s1; - if (strncmp (++s2, "zllo", 6) >= 0 || s2 != s1+1) - abort(); - s2 = s1; - if (strncmp ("zllo", ++s2, 6) <= 0 || s2 != s1+1) - abort(); - - s2 = s1; - if (strncmp (++s2, "allo", 3) <= 0 || s2 != s1+1) - abort(); - s2 = s1; - if (strncmp ("allo", ++s2, 3) >= 0 || s2 != s1+1) - abort(); - s2 = s1; - if (strncmp (++s2, "allo", 4) <= 0 || s2 != s1+1) - abort(); - s2 = s1; - if (strncmp ("allo", ++s2, 4) >= 0 || s2 != s1+1) - abort(); - s2 = s1; - if (strncmp (++s2, "allo", 5) <= 0 || s2 != s1+1) - abort(); - s2 = s1; - if (strncmp ("allo", ++s2, 5) >= 0 || s2 != s1+1) - abort(); - s2 = s1; - if (strncmp (++s2, "allo", 6) <= 0 || s2 != s1+1) - abort(); - s2 = s1; - if (strncmp ("allo", ++s2, 6) >= 0 || s2 != s1+1) - abort(); - - s2 = s1; n = 2; x = 1; - if (strncmp (++s2, s1+(x&3), ++n) != 0 || s2 != s1+1 || n != 3) - abort(); - s2 = s1; n = 2; x = 1; - if (strncmp (s1+(x&3), ++s2, ++n) != 0 || s2 != s1+1 || n != 3) - abort(); - s2 = s1; n = 3; x = 1; - if (strncmp (++s2, s1+(x&3), ++n) != 0 || s2 != s1+1 || n != 4) - abort(); - s2 = s1; n = 3; x = 1; - if (strncmp (s1+(x&3), ++s2, ++n) != 0 || s2 != s1+1 || n != 4) - abort(); - s2 = s1; n = 4; x = 1; - if (strncmp (++s2, s1+(x&3), ++n) != 0 || s2 != s1+1 || n != 5) - abort(); - s2 = s1; n = 4; x = 1; - if (strncmp (s1+(x&3), ++s2, ++n) != 0 || s2 != s1+1 || n != 5) - abort(); - s2 = s1; n = 5; x = 1; - if (strncmp (++s2, s1+(x&3), ++n) != 0 || s2 != s1+1 || n != 6) - abort(); - s2 = s1; n = 5; x = 1; - if (strncmp (s1+(x&3), ++s2, ++n) != 0 || s2 != s1+1 || n != 6) - abort(); - - s2 = s1; n = 2; - if (strncmp (++s2, "zllo", ++n) >= 0 || s2 != s1+1 || n != 3) - abort(); - s2 = s1; n = 2; x = 1; - if (strncmp ("zllo", ++s2, ++n) <= 0 || s2 != s1+1 || n != 3) - abort(); - s2 = s1; n = 3; x = 1; - if (strncmp (++s2, "zllo", ++n) >= 0 || s2 != s1+1 || n != 4) - abort(); - s2 = s1; n = 3; x = 1; - if (strncmp ("zllo", ++s2, ++n) <= 0 || s2 != s1+1 || n != 4) - abort(); - s2 = s1; n = 4; x = 1; - if (strncmp (++s2, "zllo", ++n) >= 0 || s2 != s1+1 || n != 5) - abort(); - s2 = s1; n = 4; x = 1; - if (strncmp ("zllo", ++s2, ++n) <= 0 || s2 != s1+1 || n != 5) - abort(); - s2 = s1; n = 5; x = 1; - if (strncmp (++s2, "zllo", ++n) >= 0 || s2 != s1+1 || n != 6) - abort(); - s2 = s1; n = 5; x = 1; - if (strncmp ("zllo", ++s2, ++n) <= 0 || s2 != s1+1 || n != 6) - abort(); - - s2 = s1; n = 2; - if (strncmp (++s2, "allo", ++n) <= 0 || s2 != s1+1 || n != 3) - abort(); - s2 = s1; n = 2; x = 1; - if (strncmp ("allo", ++s2, ++n) >= 0 || s2 != s1+1 || n != 3) - abort(); - s2 = s1; n = 3; x = 1; - if (strncmp (++s2, "allo", ++n) <= 0 || s2 != s1+1 || n != 4) - abort(); - s2 = s1; n = 3; x = 1; - if (strncmp ("allo", ++s2, ++n) >= 0 || s2 != s1+1 || n != 4) - abort(); - s2 = s1; n = 4; x = 1; - if (strncmp (++s2, "allo", ++n) <= 0 || s2 != s1+1 || n != 5) - abort(); - s2 = s1; n = 4; x = 1; - if (strncmp ("allo", ++s2, ++n) >= 0 || s2 != s1+1 || n != 5) - abort(); - s2 = s1; n = 5; x = 1; - if (strncmp (++s2, "allo", ++n) <= 0 || s2 != s1+1 || n != 6) - abort(); - s2 = s1; n = 5; x = 1; - if (strncmp ("allo", ++s2, ++n) >= 0 || s2 != s1+1 || n != 6) - 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