* 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
This commit is contained in:
Zack Weinberg 2004-07-03 02:16:50 +00:00 committed by Zack Weinberg
parent e1e93ad8ab
commit 50c6431753
83 changed files with 983 additions and 760 deletions

View File

@ -1,3 +1,131 @@
2004-07-02 Zack Weinberg <zack@codesourcery.com>
* 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 <mark@codesourcery.com>
PR c++/16240

View File

@ -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)

View File

@ -0,0 +1 @@
#include "lib/abs.c"

View File

@ -21,12 +21,10 @@ extern long labs (long);
extern long long llabs (long long);
extern intmax_t imaxabs (intmax_t);
extern void abort (void);
extern void exit (int);
extern void link_error (void);
extern void link_failure (void);
int
main (void)
void
main_test (void)
{
/* For each type, test both runtime and compile time (constant folding)
optimization. */
@ -39,122 +37,81 @@ main (void)
if (abs (i0) != 0)
abort ();
if (abs (0) != 0)
link_failure ();
link_error ();
if (abs (i1) != 1)
abort ();
if (abs (1) != 1)
link_failure ();
link_error ();
if (abs (im1) != 1)
abort ();
if (abs (-1) != 1)
link_failure ();
link_error ();
if (abs (imin) != INT_MAX)
abort ();
if (abs (-INT_MAX) != INT_MAX)
link_failure ();
link_error ();
if (abs (imax) != INT_MAX)
abort ();
if (abs (INT_MAX) != INT_MAX)
link_failure ();
link_error ();
if (labs (l0) != 0L)
abort ();
if (labs (0L) != 0L)
link_failure ();
link_error ();
if (labs (l1) != 1L)
abort ();
if (labs (1L) != 1L)
link_failure ();
link_error ();
if (labs (lm1) != 1L)
abort ();
if (labs (-1L) != 1L)
link_failure ();
link_error ();
if (labs (lmin) != LONG_MAX)
abort ();
if (labs (-LONG_MAX) != LONG_MAX)
link_failure ();
link_error ();
if (labs (lmax) != LONG_MAX)
abort ();
if (labs (LONG_MAX) != LONG_MAX)
link_failure ();
link_error ();
if (llabs (ll0) != 0LL)
abort ();
if (llabs (0LL) != 0LL)
link_failure ();
link_error ();
if (llabs (ll1) != 1LL)
abort ();
if (llabs (1LL) != 1LL)
link_failure ();
link_error ();
if (llabs (llm1) != 1LL)
abort ();
if (llabs (-1LL) != 1LL)
link_failure ();
link_error ();
if (llabs (llmin) != __LONG_LONG_MAX__)
abort ();
if (llabs (-__LONG_LONG_MAX__) != __LONG_LONG_MAX__)
link_failure ();
link_error ();
if (llabs (llmax) != __LONG_LONG_MAX__)
abort ();
if (llabs (__LONG_LONG_MAX__) != __LONG_LONG_MAX__)
link_failure ();
link_error ();
if (imaxabs (imax0) != 0)
abort ();
if (imaxabs (0) != 0)
link_failure ();
link_error ();
if (imaxabs (imax1) != 1)
abort ();
if (imaxabs (1) != 1)
link_failure ();
link_error ();
if (imaxabs (imaxm1) != 1)
abort ();
if (imaxabs (-1) != 1)
link_failure ();
link_error ();
if (imaxabs (imaxmin) != INTMAX_MAX)
abort ();
if (imaxabs (-INTMAX_MAX) != INTMAX_MAX)
link_failure ();
link_error ();
if (imaxabs (imaxmax) != INTMAX_MAX)
abort ();
if (imaxabs (INTMAX_MAX) != INTMAX_MAX)
link_failure ();
exit (0);
link_error ();
}
/* 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

View File

@ -0,0 +1 @@
#include "lib/abs.c"

View File

@ -17,12 +17,10 @@ typedef long long intmax_t;
#endif
extern void abort (void);
extern void exit (int);
extern void link_error (void);
extern void link_failure (void);
int
main (void)
void
main_test (void)
{
/* For each type, test both runtime and compile time (constant folding)
optimization. */
@ -35,122 +33,81 @@ main (void)
if (__builtin_abs (i0) != 0)
abort ();
if (__builtin_abs (0) != 0)
link_failure ();
link_error ();
if (__builtin_abs (i1) != 1)
abort ();
if (__builtin_abs (1) != 1)
link_failure ();
link_error ();
if (__builtin_abs (im1) != 1)
abort ();
if (__builtin_abs (-1) != 1)
link_failure ();
link_error ();
if (__builtin_abs (imin) != INT_MAX)
abort ();
if (__builtin_abs (-INT_MAX) != INT_MAX)
link_failure ();
link_error ();
if (__builtin_abs (imax) != INT_MAX)
abort ();
if (__builtin_abs (INT_MAX) != INT_MAX)
link_failure ();
link_error ();
if (__builtin_labs (l0) != 0L)
abort ();
if (__builtin_labs (0L) != 0L)
link_failure ();
link_error ();
if (__builtin_labs (l1) != 1L)
abort ();
if (__builtin_labs (1L) != 1L)
link_failure ();
link_error ();
if (__builtin_labs (lm1) != 1L)
abort ();
if (__builtin_labs (-1L) != 1L)
link_failure ();
link_error ();
if (__builtin_labs (lmin) != LONG_MAX)
abort ();
if (__builtin_labs (-LONG_MAX) != LONG_MAX)
link_failure ();
link_error ();
if (__builtin_labs (lmax) != LONG_MAX)
abort ();
if (__builtin_labs (LONG_MAX) != LONG_MAX)
link_failure ();
link_error ();
if (__builtin_llabs (ll0) != 0LL)
abort ();
if (__builtin_llabs (0LL) != 0LL)
link_failure ();
link_error ();
if (__builtin_llabs (ll1) != 1LL)
abort ();
if (__builtin_llabs (1LL) != 1LL)
link_failure ();
link_error ();
if (__builtin_llabs (llm1) != 1LL)
abort ();
if (__builtin_llabs (-1LL) != 1LL)
link_failure ();
link_error ();
if (__builtin_llabs (llmin) != __LONG_LONG_MAX__)
abort ();
if (__builtin_llabs (-__LONG_LONG_MAX__) != __LONG_LONG_MAX__)
link_failure ();
link_error ();
if (__builtin_llabs (llmax) != __LONG_LONG_MAX__)
abort ();
if (__builtin_llabs (__LONG_LONG_MAX__) != __LONG_LONG_MAX__)
link_failure ();
link_error ();
if (__builtin_imaxabs (imax0) != 0)
abort ();
if (__builtin_imaxabs (0) != 0)
link_failure ();
link_error ();
if (__builtin_imaxabs (imax1) != 1)
abort ();
if (__builtin_imaxabs (1) != 1)
link_failure ();
link_error ();
if (__builtin_imaxabs (imaxm1) != 1)
abort ();
if (__builtin_imaxabs (-1) != 1)
link_failure ();
link_error ();
if (__builtin_imaxabs (imaxmin) != INTMAX_MAX)
abort ();
if (__builtin_imaxabs (-INTMAX_MAX) != INTMAX_MAX)
link_failure ();
link_error ();
if (__builtin_imaxabs (imaxmax) != INTMAX_MAX)
abort ();
if (__builtin_imaxabs (INTMAX_MAX) != INTMAX_MAX)
link_failure ();
exit (0);
link_error ();
}
/* 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

View File

@ -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;
}

View File

@ -14,12 +14,10 @@ extern double cimag (double _Complex);
extern long double cimagl (long double _Complex);
extern void abort (void);
extern void exit (int);
extern void link_error (void);
extern void link_failure (void);
int
main (void)
void
main_test (void)
{
/* For each type, test both runtime and compile time (constant folding)
optimization. */
@ -32,144 +30,73 @@ main (void)
if (__builtin_conjf (fc) != 1.0F - 2.0iF)
abort ();
if (conjf (1.0F + 2.0iF) != 1.0F - 2.0iF)
link_failure ();
link_error ();
if (__builtin_conjf (1.0F + 2.0iF) != 1.0F - 2.0iF)
link_failure ();
link_error ();
if (crealf (fc) != 1.0F)
abort ();
if (__builtin_crealf (fc) != 1.0F)
abort ();
if (crealf (1.0F + 2.0iF) != 1.0F)
link_failure ();
link_error ();
if (__builtin_crealf (1.0F + 2.0iF) != 1.0F)
link_failure ();
link_error ();
if (cimagf (fc) != 2.0F)
abort ();
if (__builtin_cimagf (fc) != 2.0F)
abort ();
if (cimagf (1.0F + 2.0iF) != 2.0F)
link_failure ();
link_error ();
if (__builtin_cimagf (1.0F + 2.0iF) != 2.0F)
link_failure ();
link_error ();
/* Test doubles. */
if (conj (dc) != 1.0 - 2.0i)
abort ();
if (__builtin_conj (dc) != 1.0 - 2.0i)
abort ();
if (conj (1.0 + 2.0i) != 1.0 - 2.0i)
link_failure ();
link_error ();
if (__builtin_conj (1.0 + 2.0i) != 1.0 - 2.0i)
link_failure ();
link_error ();
if (creal (dc) != 1.0)
abort ();
if (__builtin_creal (dc) != 1.0)
abort ();
if (creal (1.0 + 2.0i) != 1.0)
link_failure ();
link_error ();
if (__builtin_creal (1.0 + 2.0i) != 1.0)
link_failure ();
link_error ();
if (cimag (dc) != 2.0)
abort ();
if (__builtin_cimag (dc) != 2.0)
abort ();
if (cimag (1.0 + 2.0i) != 2.0)
link_failure ();
link_error ();
if (__builtin_cimag (1.0 + 2.0i) != 2.0)
link_failure ();
link_error ();
/* Test long doubles. */
if (conjl (ldc) != 1.0L - 2.0iL)
abort ();
if (__builtin_conjl (ldc) != 1.0L - 2.0iL)
abort ();
if (conjl (1.0L + 2.0iL) != 1.0L - 2.0iL)
link_failure ();
link_error ();
if (__builtin_conjl (1.0L + 2.0iL) != 1.0L - 2.0iL)
link_failure ();
link_error ();
if (creall (ldc) != 1.0L)
abort ();
if (__builtin_creall (ldc) != 1.0L)
abort ();
if (creall (1.0L + 2.0iL) != 1.0L)
link_failure ();
link_error ();
if (__builtin_creall (1.0L + 2.0iL) != 1.0L)
link_failure ();
link_error ();
if (cimagl (ldc) != 2.0L)
abort ();
if (__builtin_cimagl (ldc) != 2.0L)
abort ();
if (cimagl (1.0L + 2.0iL) != 2.0L)
link_failure ();
link_error ();
if (__builtin_cimagl (1.0L + 2.0iL) != 2.0L)
link_failure ();
exit (0);
link_error ();
}
/* 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

View File

@ -0,0 +1 @@
#include "lib/fprintf.c"

View File

@ -6,10 +6,10 @@
Written by Kaveh R. Ghazi, 1/7/2001. */
#include <stdio.h>
extern int fprintf (FILE *, const char *, ...);
extern void abort(void);
int main()
void
main_test (void)
{
FILE *s_array[] = {stdout, NULL}, **s_ptr = s_array;
const char *const s1 = "hello world";
@ -49,18 +49,4 @@ int main()
/* Test at least one instance of the __builtin_ style. We do this
to ensure that it works and that the prototype is correct. */
__builtin_fprintf (*s_ptr, "%s", "hello world\n");
return 0;
}
#ifdef __OPTIMIZE__
/* When optimizing, all the above cases should be transformed into
something else. So any remaining calls to the original function
should abort. */
__attribute__ ((noinline))
static int
fprintf (FILE *stream, const char *string, ...)
{
abort();
}
#endif

View File

@ -0,0 +1,17 @@
#include <stdio.h>
#include <stddef.h>
extern int inside_main;
extern size_t strlen(const char *);
int
fputs(const char *string, FILE *stream)
{
size_t n = strlen(string);
size_t r;
#if defined __OPTIMIZE__ && !defined __OPTIMIZE_SIZE__
if (inside_main)
abort();
#endif
r = fwrite (string, 1, n, stream);
return n > r ? EOF : 0;
}

View File

@ -7,14 +7,11 @@
#include <stdio.h>
extern void abort(void);
/* Declare this without args because that's what gcc does internally.
We want to make sure it works without a helpful prototype from us.
If stdio.h provides one, that is okay. */
extern int fputs();
int i;
int main()
void
main_test(void)
{
FILE *s_array[] = {stdout, NULL}, **s_ptr = s_array;
const char *const s1 = "hello world";
@ -61,18 +58,4 @@ int main()
fputs (--i ? "\n" : "\n", *--s_ptr);
if (s_ptr != s_array || i != 0)
abort();
return 0;
}
#if defined (__OPTIMIZE__) && ! defined (__OPTIMIZE_SIZE__)
/* When optimizing, all the above cases should be transformed into
something else. So any remaining calls to the original function
should abort. */
__attribute__ ((noinline))
static int
fputs(const char *string, FILE *stream)
{
abort();
}
#endif

View File

@ -0,0 +1,50 @@
extern int inside_main;
extern void abort (void);
#ifdef __OPTIMIZE__
#define ABORT_INSIDE_MAIN do { if (inside_main) abort (); } while (0)
#else
#define ABORT_INSIDE_MAIN do { } while (0)
#endif
/* These next definitions are kludges. When GCC has a <stdint.h> it
should be used.
*/
#include <limits.h>
#if INT_MAX == __LONG_LONG_MAX__
typedef int intmax_t;
#define INTMAX_MAX INT_MAX
#elif LONG_MAX == __LONG_LONG_MAX__
typedef long intmax_t;
#define INTMAX_MAX LONG_MAX
#else
typedef long long intmax_t;
#define INTMAX_MAX __LONG_LONG_MAX__
#endif
int
abs (int x)
{
ABORT_INSIDE_MAIN;
return x < 0 ? -x : x;
}
long
labs (long x)
{
ABORT_INSIDE_MAIN;
return x < 0 ? -x : x;
}
long long
llabs (long long x)
{
ABORT_INSIDE_MAIN;
return x < 0 ? -x : x;
}
intmax_t
imaxabs (intmax_t x)
{
ABORT_INSIDE_MAIN;
return x < 0 ? -x : x;
}

View File

@ -0,0 +1,18 @@
#include <stdio.h>
#include <stdarg.h>
extern int inside_main;
int
fprintf (FILE *fp, const char *string, ...)
{
va_list ap;
int r;
#ifdef __OPTIMIZE__
if (inside_main)
abort();
#endif
va_start (ap, string);
r = vfprintf (fp, string, ap);
va_end (ap);
return r;
}

View File

@ -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

View File

@ -0,0 +1,19 @@
#include <stdio.h>
#include <stdarg.h>
extern int inside_main;
int
printf (const char *string, ...)
{
va_list ap;
int r;
#ifdef __OPTIMIZE__
if (inside_main)
abort();
#endif
va_start (ap, string);
r = vprintf (string, ap);
va_end (ap);
return r;
}

View File

@ -0,0 +1,20 @@
#include <stdio.h>
#include <stdarg.h>
extern int inside_main;
int
sprintf (char *buf, const char *fmt, ...)
{
va_list ap;
int r;
#ifdef __OPTIMIZE__
if (inside_main)
abort ();
#endif
va_start (ap, fmt);
r = vsprintf (buf, fmt, ap);
va_end (ap);
return r;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -4,15 +4,17 @@
On architectures with a cmpstrsi instruction, this test doesn't determine
which optimization is being performed, but it does check for correctness.
Written by Roger Sayle, 12/02/2001. */
Written by Roger Sayle, 12/02/2001.
Additional tests by Roger Sayle after PR 3508, 12/26/2001. */
extern void abort (void);
typedef __SIZE_TYPE__ size_t;
extern int memcmp (const void *, const void *, size_t);
extern char *strcpy (char *, const char *);
extern void link_error (void);
int
main ()
void
main_test (void)
{
char str[8];
@ -30,18 +32,10 @@ main ()
if ( memcmp (str+2, str, 1) <= 0 )
abort ();
return 0;
if (memcmp ("abcd", "efgh", 4) >= 0)
link_error ();
if (memcmp ("abcd", "abcd", 4) != 0)
link_error ();
if (memcmp ("efgh", "abcd", 4) <= 0)
link_error ();
}
#ifdef __OPTIMIZE__
/* When optimizing, all the above cases should be transformed into
something else. So any remaining calls to the original function
should abort. */
__attribute__ ((noinline))
static int
memcmp (const void *p1, const void *p2, size_t len)
{
abort ();
}
#endif

View File

@ -8,7 +8,6 @@ extern void abort (void);
typedef __SIZE_TYPE__ size_t;
extern void *mempcpy (void *, const void *, size_t);
extern int memcmp (const void *, const void *, size_t);
extern char *stpcpy (char *, const char *);
extern int inside_main;
long buf1[64];
@ -16,7 +15,7 @@ char *buf2 = (char *) (buf1 + 32);
long buf5[20];
char buf7[20];
int
void
__attribute__((noinline))
test (long *buf3, char *buf4, char *buf6, int n)
{
@ -141,21 +140,6 @@ test (long *buf3, char *buf4, char *buf6, int n)
if (mempcpy (buf4 + 14, buf6, n + 2) != buf2 + 16
|| memcmp (buf2, "aBcdRSTUVWkSmnrsq\0", 19))
abort ();
/* Now stpcpy tests. */
if (stpcpy ((char *) buf3, "abcdefghijklmnop") != (char *) buf1 + 16
|| memcmp (buf1, "abcdefghijklmnop", 17))
abort ();
if (__builtin_stpcpy ((char *) buf3, "ABCDEFG") != (char *) buf1 + 7
|| memcmp (buf1, "ABCDEFG\0ijklmnop", 17))
abort ();
if (stpcpy ((char *) buf3 + i++, "x") != (char *) buf1 + 5
|| memcmp (buf1, "ABCDx\0G\0ijklmnop", 17))
abort ();
return 0;
}
void

View File

@ -1,12 +1,10 @@
/* Copyright (C) 2003 Free Software Foundation.
Ensure builtin mempcpy and stpcpy perform correctly.
Ensure builtin mempcpy performs correctly.
Written by Kaveh Ghazi, 4/11/2003. */
extern void abort (void);
extern char *strcpy (char *, const char *);
extern char *stpcpy (char *, const char *);
typedef __SIZE_TYPE__ size_t;
extern size_t strlen(const char *);
extern void *memcpy (void *, const void *, size_t);
@ -32,55 +30,39 @@ main_test (void)
inside_main = 0;
#endif
if (stpcpy (p, "abcde") != p + 5 || memcmp (p, "abcde", 6))
abort ();
if (stpcpy (p + 16, "vwxyz" + 1) != p + 16 + 4 || memcmp (p + 16, "wxyz", 5))
abort ();
if (stpcpy (p + 1, "") != p + 1 + 0 || memcmp (p, "a\0cde", 6))
abort ();
if (stpcpy (p + 3, "fghij") != p + 3 + 5 || memcmp (p, "a\0cfghij", 9))
abort ();
if (mempcpy (p, "ABCDE", 6) != p + 6 || memcmp (p, "ABCDE", 6))
abort ();
if (mempcpy (p + 16, "VWX" + 1, 2) != p + 16 + 2 || memcmp (p + 16, "WXyz", 5))
if (mempcpy (p + 16, "VWX" + 1, 2) != p + 16 + 2
|| memcmp (p + 16, "WX\0\0", 5))
abort ();
if (mempcpy (p + 1, "", 1) != p + 1 + 1 || memcmp (p, "A\0CDE", 6))
abort ();
if (mempcpy (p + 3, "FGHI", 4) != p + 3 + 4 || memcmp (p, "A\0CFGHIj", 9))
if (mempcpy (p + 3, "FGHI", 4) != p + 3 + 4 || memcmp (p, "A\0CFGHI", 8))
abort ();
i = 8;
memcpy (p + 20, "qrstu", 6);
if (stpcpy ((i++, p + 20 + 1), "23") != (p + 20 + 1 + 2) || i != 9 || memcmp (p + 20, "q23\0u", 6))
abort ();
memcpy (p + 25, "QRSTU", 6);
if (mempcpy (p + 25 + 1, s1, 3) != (p + 25 + 1 + 3) || memcmp (p + 25, "Q123U", 6))
if (mempcpy (p + 25 + 1, s1, 3) != (p + 25 + 1 + 3)
|| memcmp (p + 25, "Q123U", 6))
abort ();
if (stpcpy (stpcpy (p, "ABCD"), "EFG") != p + 7 || memcmp (p, "ABCDEFG", 8))
abort();
if (mempcpy (mempcpy (p, "abcdEFG", 4), "efg", 4) != p + 8 || memcmp (p, "abcdefg", 8))
if (mempcpy (mempcpy (p, "abcdEFG", 4), "efg", 4) != p + 8
|| memcmp (p, "abcdefg", 8))
abort();
/* Test at least one instance of the __builtin_ style. We do this
to ensure that it works and that the prototype is correct. */
if (__builtin_stpcpy (p, "abcde") != p + 5 || memcmp (p, "abcde", 6))
abort ();
if (__builtin_mempcpy (p, "ABCDE", 6) != p + 6 || memcmp (p, "ABCDE", 6))
abort ();
/* If the result of stpcpy/mempcpy is ignored, gcc should use
strcpy/memcpy. This should be optimized always, so set inside_main
again. */
/* If the result of mempcpy is ignored, gcc should use memcpy.
This should be optimized always, so set inside_main again. */
inside_main = 1;
stpcpy (p + 3, s2);
if (memcmp (p, "ABCdefg", 8))
abort ();
mempcpy (p + 5, s3, 1);
if (memcmp (p, "ABCdeFg", 8))
if (memcmp (p, "ABCDEFg", 8))
abort ();
mempcpy (p + 6, s3 + 1, l1);
if (memcmp (p, "ABCdeFG", 8))
mempcpy (p + 6, s1 + 1, l1);
if (memcmp (p, "ABCDEF2", 8))
abort ();
}

View File

@ -0,0 +1 @@
#include "lib/memset.c"

View File

@ -0,0 +1 @@
#include "lib/printf.c"

View File

@ -8,7 +8,8 @@
extern int printf (const char *, ...);
extern void abort(void);
int main()
void
main_test (void)
{
const char *const s1 = "hello world";
const char *const s2[] = { s1, 0 }, *const*s3;
@ -37,18 +38,4 @@ int main()
prototypes are set correctly too. */
__builtin_putchar ('\n');
__builtin_puts ("hello");
return 0;
}
#ifdef __OPTIMIZE__
/* When optimizing, all the above cases should be transformed into
something else. So any remaining calls to the original function
should abort. */
__attribute__ ((noinline))
static int
printf (const char *string, ...)
{
abort();
}
#endif

View File

@ -0,0 +1 @@
#include "lib/sprintf.c"

View File

@ -39,7 +39,8 @@ void test5(char *ptr)
}
int main()
void
main_test (void)
{
memset (buffer, 'A', 32);
test1 ();
@ -67,19 +68,4 @@ int main()
test5 ("barf");
if (memcmp(buffer, "barf", 5) || buffer[5] != 'A')
abort ();
return 0;
}
#ifdef __OPTIMIZE__
/* When optimizing, all the above cases should be transformed into
something else. So any remaining calls to the original function
should abort. */
__attribute__ ((noinline))
static int
sprintf (char *buf, const char *fmt, ...)
{
abort ();
}
#endif

View File

@ -0,0 +1 @@
#include "lib/strcmp.c"

View File

@ -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 ();
}

View File

@ -0,0 +1 @@
#include "lib/strcpy.c"

View File

@ -12,7 +12,8 @@ extern int memcmp (const void *, const void *, size_t);
char p[32] = "";
int main()
void
main_test (void)
{
if (strcpy (p, "abcde") != p || memcmp (p, "abcde", 6))
abort ();
@ -37,18 +38,4 @@ int main()
abort ();
if (__builtin_memcpy (p, "ABCDE", 6) != p || memcmp (p, "ABCDE", 6))
abort ();
return 0;
}
#ifdef __OPTIMIZE__
/* When optimizing, all the above cases should be transformed into
something else. So any remaining calls to the original function
should abort. */
__attribute__ ((noinline))
static char *
strcpy (char *d, const char *s)
{
abort ();
}
#endif

View File

@ -0,0 +1 @@
#include "lib/strcspn.c"

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2000 Free Software Foundation.
/* Copyright (C) 2000, 2004 Free Software Foundation.
Ensure all expected transformations of builtin strcspn occur and
perform correctly.
@ -10,7 +10,8 @@ typedef __SIZE_TYPE__ size_t;
extern size_t strcspn (const char *, const char *);
extern char *strcpy (char *, const char *);
int main ()
void
main_test (void)
{
const char *const s1 = "hello world";
char dst[64], *d2;
@ -50,18 +51,4 @@ int main ()
to ensure that it works and that the prototype is correct. */
if (__builtin_strcspn (s1, "z") != 11)
abort();
return 0;
}
#ifdef __OPTIMIZE__
/* When optimizing, all the above cases should be transformed into
something else. So any remaining calls to the original function
should abort. */
__attribute__ ((noinline))
static size_t
strcspn (const char *s1, const char *s2)
{
abort();
}
#endif

View File

@ -1,3 +0,0 @@
#include "lib/strrchr.c"
#include "lib/strlen.c"
#include "lib/strcmp.c"

View File

@ -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 ();
}

View File

@ -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

View File

@ -8,7 +8,6 @@ typedef __SIZE_TYPE__ size_t;
extern char *strcpy (char *, const char *);
extern int memcmp (const void *, const void *, size_t);
extern void abort (void);
extern void exit (int);
extern int inside_main;
size_t g, h, i, j, k, l;

View File

@ -0,0 +1 @@
#include "lib/strlen.c"

View File

@ -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 ();
}

View File

@ -0,0 +1 @@
#include "lib/strncat.c"

View File

@ -12,7 +12,8 @@ extern char *strcpy (char *, const char *);
extern int strcmp (const char *, const char *);
int x = 123;
int main ()
void
main_test (void)
{
const char *const s1 = "hello world";
const char *const s2 = "";
@ -68,18 +69,4 @@ int main ()
strcpy (dst, s1);
if (__builtin_strncat (dst, "", 100) != dst || strcmp (dst, s1))
abort();
return 0;
}
#ifdef __OPTIMIZE__
/* When optimizing, all the above cases should be transformed into
something else. So any remaining calls to the original function
should abort. */
__attribute__ ((noinline))
static char *
strncat (char *s1, const char *s2, size_t n)
{
abort();
}
#endif

View File

@ -0,0 +1 @@
#include "lib/strncmp.c"

View File

@ -9,62 +9,13 @@ extern void abort (void);
typedef __SIZE_TYPE__ size_t;
extern int strncmp (const char *, const char *, size_t);
int main ()
void
main_test (void)
{
const char *const s1 = "hello world";
const char *s2, *s3;
int n = 6, x;
if (strncmp (s1, "hello world", 12) != 0)
abort();
if (strncmp ("hello world", s1, 12) != 0)
abort();
if (strncmp ("hello", "hello", 6) != 0)
abort();
if (strncmp ("hello", "hello", 2) != 0)
abort();
if (strncmp ("hello", "hello", 100) != 0)
abort();
if (strncmp (s1+10, "d", 100) != 0)
abort();
if (strncmp (10+s1, "d", 100) != 0)
abort();
if (strncmp ("d", s1+10, 1) != 0)
abort();
if (strncmp ("d", 10+s1, 1) != 0)
abort();
if (strncmp ("hello", "aaaaa", 100) <= 0)
abort();
if (strncmp ("aaaaa", "hello", 100) >= 0)
abort();
if (strncmp ("hello", "aaaaa", 1) <= 0)
abort();
if (strncmp ("aaaaa", "hello", 1) >= 0)
abort();
s2 = s1; s3 = s1+4;
if (strncmp (++s2, ++s3, 0) != 0 || s2 != s1+1 || s3 != s1+5)
abort();
s2 = s1;
if (strncmp (++s2, "", 1) <= 0 || s2 != s1+1)
abort();
if (strncmp ("", ++s2, 1) >= 0 || s2 != s1+2)
abort();
if (strncmp (++s2, "", 100) <= 0 || s2 != s1+3)
abort();
if (strncmp ("", ++s2, 100) >= 0 || s2 != s1+4)
abort();
if (strncmp (++s2+6, "", 100) != 0 || s2 != s1+5)
abort();
if (strncmp ("", ++s2+5, 100) != 0 || s2 != s1+6)
abort();
if (strncmp ("ozz", ++s2, 1) != 0 || s2 != s1+7)
abort();
if (strncmp (++s2, "rzz", 1) != 0 || s2 != s1+8)
abort();
s2 = s1; s3 = s1+4;
if (strncmp (++s2, ++s3+2, 1) >= 0 || s2 != s1+1 || s3 != s1+5)
abort();
#if !defined(__OPTIMIZE__) || (defined(__i386__) && !defined(__OPTIMIZE_SIZE__))
/* These tests work on platforms which support cmpstrsi. We test it
at -O0 on all platforms to ensure the strncmp logic is correct. */
@ -219,23 +170,4 @@ int main ()
abort();
#endif
/* Test at least one instance of the __builtin_ style. We do this
to ensure that it works and that the prototype is correct. */
if (__builtin_strncmp ("hello", "a", 100) <= 0)
abort();
return 0;
}
#ifdef __OPTIMIZE__
/* When optimizing, all the above cases should be transformed into
something else. So any remaining calls to the original function
should abort. */
__attribute__ ((noinline))
static int
strncmp(const char *s1, const char *s2, size_t n)
{
abort();
}
#endif

View File

@ -0,0 +1 @@
#include "lib/strncmp.c"

View File

@ -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();
}

View File

@ -0,0 +1 @@
#include "lib/strncpy.c"

View File

@ -14,7 +14,8 @@ extern void *memset (void *, int, size_t);
int i;
int main ()
void
main_test (void)
{
const char *const src = "hello world";
const char *src2;
@ -72,15 +73,3 @@ int main ()
return 0;
}
#ifdef __OPTIMIZE__
/* When optimizing, all the above cases should be transformed into
something else. So any remaining calls to the original function
should abort. */
__attribute__ ((noinline))
static char *
strncpy(char *s1, const char *s2, size_t n)
{
abort();
}
#endif

View File

@ -0,0 +1 @@
#include "lib/strpbrk.c"

View File

@ -34,22 +34,9 @@ void fn (const char *foo, const char *const *bar)
abort();
}
int main()
void
main_test (void)
{
const char *const foo[] = { "hello world", "bye bye world" };
fn (foo[0], foo + 1);
return 0;
}
#ifdef __OPTIMIZE__
/* When optimizing, all the above cases should be transformed into
something else. So any remaining calls to the original function
should abort. */
__attribute__ ((noinline))
static char *
strpbrk(const char *s1, const char *s2)
{
abort();
}
#endif

View File

@ -0,0 +1 @@
#include "lib/stpcpy.c"

View File

@ -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);
}

View File

@ -0,0 +1 @@
#include "lib/stpcpy.c"

View File

@ -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 ();
}

View File

@ -0,0 +1 @@
#include "lib/strrchr.c"

View File

@ -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 ();
}

View File

@ -0,0 +1 @@
#include "lib/strspn.c"

View File

@ -10,7 +10,8 @@ typedef __SIZE_TYPE__ size_t;
extern size_t strspn (const char *, const char *);
extern char *strcpy (char *, const char *);
int main ()
void
main_test (void)
{
const char *const s1 = "hello world";
char dst[64], *d2;
@ -50,18 +51,4 @@ int main ()
to ensure that it works and that the prototype is correct. */
if (__builtin_strspn (s1, "hello") != 5)
abort();
return 0;
}
#ifdef __OPTIMIZE__
/* When optimizing, all the above cases should be transformed into
something else. So any remaining calls to the original function
should abort. */
__attribute__ ((noinline))
static size_t
strspn (const char *s1, const char *s2)
{
abort();
}
#endif

View File

@ -0,0 +1 @@
#include "lib/strstr.c"

View File

@ -8,7 +8,8 @@
extern void abort(void);
extern char *strstr (const char *, const char *);
int main()
void
main_test (void)
{
const char *const foo = "hello world";
@ -29,18 +30,4 @@ int main()
to ensure that it works and that the prototype is correct. */
if (__builtin_strstr (foo + 1, "world") != foo + 6)
abort();
return 0;
}
#ifdef __OPTIMIZE__
/* When optimizing, all the above cases should be transformed into
something else. So any remaining calls to the original function
should abort. */
__attribute__ ((noinline))
static char *
strstr(const char *s1, const char *s2)
{
abort();
}
#endif

View File

@ -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

View File

@ -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