diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/gcc.c-torture/execute/builtins/lib | |
download | cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2 cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/gcc.c-torture/execute/builtins/lib')
27 files changed, 1118 insertions, 0 deletions
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 000000000..1e0857f73 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/abs.c @@ -0,0 +1,41 @@ +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 + +typedef __INTMAX_TYPE__ intmax_t; + +__attribute__ ((__noinline__)) +int +abs (int x) +{ + ABORT_INSIDE_MAIN; + return x < 0 ? -x : x; +} + +__attribute__ ((__noinline__)) +long +labs (long x) +{ + ABORT_INSIDE_MAIN; + return x < 0 ? -x : x; +} + +__attribute__ ((__noinline__)) +long long +llabs (long long x) +{ + ABORT_INSIDE_MAIN; + return x < 0 ? -x : x; +} + +__attribute__ ((__noinline__)) +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/bfill.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/bfill.c new file mode 100644 index 000000000..deb6cf522 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/bfill.c @@ -0,0 +1,16 @@ +extern int inside_main; + +__attribute__ ((__noinline__)) +void +bfill (void *s, __SIZE_TYPE__ n, int ch) +{ + char *p; + + for (p = s; n-- > 0; p++) + *p = ch; + +#ifdef __OPTIMIZE__ + if (inside_main) + abort (); +#endif +} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/bzero.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/bzero.c new file mode 100644 index 000000000..a02b5358b --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/bzero.c @@ -0,0 +1,16 @@ +extern int inside_main; + +__attribute__ ((__noinline__)) +void +bzero (void *s, __SIZE_TYPE__ n) +{ + char *p; + + for (p = s; n-- > 0; p++) + *p = 0; + +#ifdef __OPTIMIZE__ + if (inside_main) + abort (); +#endif +} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/chk.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/chk.c new file mode 100644 index 000000000..e5197902b --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/chk.c @@ -0,0 +1,478 @@ +#include <stdarg.h> +#ifdef __unix__ +#include <sys/types.h> +#endif + +extern void abort (void); + +extern int inside_main; +void *chk_fail_buf[256] __attribute__((aligned (16))); +volatile int chk_fail_allowed, chk_calls; +volatile int memcpy_disallowed, mempcpy_disallowed, memmove_disallowed; +volatile int memset_disallowed, strcpy_disallowed, stpcpy_disallowed; +volatile int strncpy_disallowed, strcat_disallowed, strncat_disallowed; +volatile int sprintf_disallowed, vsprintf_disallowed; +volatile int snprintf_disallowed, vsnprintf_disallowed; +extern __SIZE_TYPE__ strlen (const char *); +extern int vsprintf (char *, const char *, va_list); + +void __attribute__((noreturn)) +__chk_fail (void) +{ + if (chk_fail_allowed) + __builtin_longjmp (chk_fail_buf, 1); + abort (); +} + +void * +memcpy (void *dst, const void *src, __SIZE_TYPE__ n) +{ + const char *srcp; + char *dstp; + +#ifdef __OPTIMIZE__ + if (memcpy_disallowed && inside_main) + abort (); +#endif + + srcp = src; + dstp = dst; + while (n-- != 0) + *dstp++ = *srcp++; + + return dst; +} + +void * +__memcpy_chk (void *dst, const void *src, __SIZE_TYPE__ n, __SIZE_TYPE__ size) +{ + /* If size is -1, GCC should always optimize the call into memcpy. */ + if (size == (__SIZE_TYPE__) -1) + abort (); + ++chk_calls; + if (n > size) + __chk_fail (); + return memcpy (dst, src, n); +} + +void * +mempcpy (void *dst, const void *src, __SIZE_TYPE__ n) +{ + const char *srcp; + char *dstp; + +#ifdef __OPTIMIZE__ + if (mempcpy_disallowed && inside_main) + abort (); +#endif + + srcp = src; + dstp = dst; + while (n-- != 0) + *dstp++ = *srcp++; + + return dstp; +} + +void * +__mempcpy_chk (void *dst, const void *src, __SIZE_TYPE__ n, __SIZE_TYPE__ size) +{ + /* If size is -1, GCC should always optimize the call into mempcpy. */ + if (size == (__SIZE_TYPE__) -1) + abort (); + ++chk_calls; + if (n > size) + __chk_fail (); + return mempcpy (dst, src, n); +} + +void * +memmove (void *dst, const void *src, __SIZE_TYPE__ n) +{ + const char *srcp; + char *dstp; + +#ifdef __OPTIMIZE__ + if (memmove_disallowed && inside_main) + abort (); +#endif + + srcp = src; + dstp = dst; + if (srcp < dstp) + while (n-- != 0) + dstp[n] = srcp[n]; + else + while (n-- != 0) + *dstp++ = *srcp++; + + return dst; +} + +void * +__memmove_chk (void *dst, const void *src, __SIZE_TYPE__ n, __SIZE_TYPE__ size) +{ + /* If size is -1, GCC should always optimize the call into memmove. */ + if (size == (__SIZE_TYPE__) -1) + abort (); + ++chk_calls; + if (n > size) + __chk_fail (); + return memmove (dst, src, n); +} + +void * +memset (void *dst, int c, __SIZE_TYPE__ n) +{ + /* Single-byte memsets should be done inline when optimisation + is enabled. */ +#ifdef __OPTIMIZE__ + if (memset_disallowed && inside_main && n < 2) + abort (); +#endif + + while (n-- != 0) + n[(char *) dst] = c; + + return dst; +} + +void * +__memset_chk (void *dst, int c, __SIZE_TYPE__ n, __SIZE_TYPE__ size) +{ + /* If size is -1, GCC should always optimize the call into memset. */ + if (size == (__SIZE_TYPE__) -1) + abort (); + ++chk_calls; + if (n > size) + __chk_fail (); + return memset (dst, c, n); +} + +char * +strcpy (char *d, const char *s) +{ + char *r = d; +#ifdef __OPTIMIZE__ + if (strcpy_disallowed && inside_main) + abort (); +#endif + while ((*d++ = *s++)); + return r; +} + +char * +__strcpy_chk (char *d, const char *s, __SIZE_TYPE__ size) +{ + /* If size is -1, GCC should always optimize the call into strcpy. */ + if (size == (__SIZE_TYPE__) -1) + abort (); + ++chk_calls; + if (strlen (s) >= size) + __chk_fail (); + return strcpy (d, s); +} + +char * +stpcpy (char *dst, const char *src) +{ +#ifdef __OPTIMIZE__ + if (stpcpy_disallowed && inside_main) + abort (); +#endif + + while (*src != 0) + *dst++ = *src++; + + *dst = 0; + return dst; +} + +char * +__stpcpy_chk (char *d, const char *s, __SIZE_TYPE__ size) +{ + /* If size is -1, GCC should always optimize the call into stpcpy. */ + if (size == (__SIZE_TYPE__) -1) + abort (); + ++chk_calls; + if (strlen (s) >= size) + __chk_fail (); + return stpcpy (d, s); +} + +char * +strncpy (char *s1, const char *s2, __SIZE_TYPE__ n) +{ + char *dest = s1; +#ifdef __OPTIMIZE__ + if (strncpy_disallowed && inside_main) + abort(); +#endif + for (; *s2 && n; n--) + *s1++ = *s2++; + while (n--) + *s1++ = 0; + return dest; +} + +char * +__strncpy_chk (char *s1, const char *s2, __SIZE_TYPE__ n, __SIZE_TYPE__ size) +{ + /* If size is -1, GCC should always optimize the call into strncpy. */ + if (size == (__SIZE_TYPE__) -1) + abort (); + ++chk_calls; + if (n > size) + __chk_fail (); + return strncpy (s1, s2, n); +} + +char * +strcat (char *dst, const char *src) +{ + char *p = dst; + +#ifdef __OPTIMIZE__ + if (strcat_disallowed && inside_main) + abort (); +#endif + + while (*p) + p++; + while ((*p++ = *src++)) + ; + return dst; +} + +char * +__strcat_chk (char *d, const char *s, __SIZE_TYPE__ size) +{ + /* If size is -1, GCC should always optimize the call into strcat. */ + if (size == (__SIZE_TYPE__) -1) + abort (); + ++chk_calls; + if (strlen (d) + strlen (s) >= size) + __chk_fail (); + return strcat (d, s); +} + +char * +strncat (char *s1, const char *s2, __SIZE_TYPE__ n) +{ + char *dest = s1; + char c; +#ifdef __OPTIMIZE__ + if (strncat_disallowed && inside_main) + abort(); +#endif + while (*s1) s1++; + c = '\0'; + while (n > 0) + { + c = *s2++; + *s1++ = c; + if (c == '\0') + return dest; + n--; + } + if (c != '\0') + *s1 = '\0'; + return dest; +} + +char * +__strncat_chk (char *d, const char *s, __SIZE_TYPE__ n, __SIZE_TYPE__ size) +{ + __SIZE_TYPE__ len = strlen (d), n1 = n; + const char *s1 = s; + + /* If size is -1, GCC should always optimize the call into strncat. */ + if (size == (__SIZE_TYPE__) -1) + abort (); + ++chk_calls; + while (len < size && n1 > 0) + { + if (*s1++ == '\0') + break; + ++len; + --n1; + } + + if (len >= size) + __chk_fail (); + return strncat (d, s, n); +} + +/* No chk test in GCC testsuite needs more bytes than this. + As we can't expect vsnprintf to be available on the target, + assume 4096 bytes is enough. */ +static char chk_sprintf_buf[4096]; + +int +__sprintf_chk (char *str, int flag, __SIZE_TYPE__ size, const char *fmt, ...) +{ + int ret; + va_list ap; + + /* If size is -1 and flag 0, GCC should always optimize the call into + sprintf. */ + if (size == (__SIZE_TYPE__) -1 && flag == 0) + abort (); + ++chk_calls; +#ifdef __OPTIMIZE__ + if (sprintf_disallowed && inside_main) + abort(); +#endif + va_start (ap, fmt); + ret = vsprintf (chk_sprintf_buf, fmt, ap); + va_end (ap); + if (ret >= 0) + { + if (ret >= size) + __chk_fail (); + memcpy (str, chk_sprintf_buf, ret + 1); + } + return ret; +} + +int +__vsprintf_chk (char *str, int flag, __SIZE_TYPE__ size, const char *fmt, + va_list ap) +{ + int ret; + + /* If size is -1 and flag 0, GCC should always optimize the call into + vsprintf. */ + if (size == (__SIZE_TYPE__) -1 && flag == 0) + abort (); + ++chk_calls; +#ifdef __OPTIMIZE__ + if (vsprintf_disallowed && inside_main) + abort(); +#endif + ret = vsprintf (chk_sprintf_buf, fmt, ap); + if (ret >= 0) + { + if (ret >= size) + __chk_fail (); + memcpy (str, chk_sprintf_buf, ret + 1); + } + return ret; +} + +int +__snprintf_chk (char *str, __SIZE_TYPE__ len, int flag, __SIZE_TYPE__ size, + const char *fmt, ...) +{ + int ret; + va_list ap; + + /* If size is -1 and flag 0, GCC should always optimize the call into + snprintf. */ + if (size == (__SIZE_TYPE__) -1 && flag == 0) + abort (); + ++chk_calls; + if (size < len) + __chk_fail (); +#ifdef __OPTIMIZE__ + if (snprintf_disallowed && inside_main) + abort(); +#endif + va_start (ap, fmt); + ret = vsprintf (chk_sprintf_buf, fmt, ap); + va_end (ap); + if (ret >= 0) + { + if (ret < len) + memcpy (str, chk_sprintf_buf, ret + 1); + else + { + memcpy (str, chk_sprintf_buf, len - 1); + str[len - 1] = '\0'; + } + } + return ret; +} + +int +__vsnprintf_chk (char *str, __SIZE_TYPE__ len, int flag, __SIZE_TYPE__ size, + const char *fmt, va_list ap) +{ + int ret; + + /* If size is -1 and flag 0, GCC should always optimize the call into + vsnprintf. */ + if (size == (__SIZE_TYPE__) -1 && flag == 0) + abort (); + ++chk_calls; + if (size < len) + __chk_fail (); +#ifdef __OPTIMIZE__ + if (vsnprintf_disallowed && inside_main) + abort(); +#endif + ret = vsprintf (chk_sprintf_buf, fmt, ap); + if (ret >= 0) + { + if (ret < len) + memcpy (str, chk_sprintf_buf, ret + 1); + else + { + memcpy (str, chk_sprintf_buf, len - 1); + str[len - 1] = '\0'; + } + } + return ret; +} + +int +snprintf (char *str, __SIZE_TYPE__ len, const char *fmt, ...) +{ + int ret; + va_list ap; + +#ifdef __OPTIMIZE__ + if (snprintf_disallowed && inside_main) + abort(); +#endif + va_start (ap, fmt); + ret = vsprintf (chk_sprintf_buf, fmt, ap); + va_end (ap); + if (ret >= 0) + { + if (ret < len) + memcpy (str, chk_sprintf_buf, ret + 1); + else if (len) + { + memcpy (str, chk_sprintf_buf, len - 1); + str[len - 1] = '\0'; + } + } + return ret; +} + +/* uClibc's vsprintf calls vsnprintf. */ +#ifndef __UCLIBC__ +int +vsnprintf (char *str, __SIZE_TYPE__ len, const char *fmt, va_list ap) +{ + int ret; + +#ifdef __OPTIMIZE__ + if (vsnprintf_disallowed && inside_main) + abort(); +#endif + ret = vsprintf (chk_sprintf_buf, fmt, ap); + if (ret >= 0) + { + if (ret < len) + memcpy (str, chk_sprintf_buf, ret + 1); + else if (len) + { + memcpy (str, chk_sprintf_buf, len - 1); + str[len - 1] = '\0'; + } + } + return ret; +} +#endif 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 000000000..853a705e8 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/fprintf.c @@ -0,0 +1,37 @@ +#include <stdio.h> +#include <stdarg.h> +extern void abort (void); +extern int inside_main; + +__attribute__ ((__noinline__)) +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; +} + +/* Locking stdio doesn't matter for the purposes of this test. */ +__attribute__ ((__noinline__)) +int +fprintf_unlocked (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 new file mode 100644 index 000000000..a9bb6c6b8 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/main.c @@ -0,0 +1,25 @@ +extern void abort(void); +extern void main_test (void); +extern void abort (void); +int inside_main; + +int +main () +{ + inside_main = 1; + main_test (); + 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/memchr.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/memchr.c new file mode 100644 index 000000000..2f15c57a7 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/memchr.c @@ -0,0 +1,22 @@ +extern void abort(void); +extern int inside_main; + +__attribute__ ((__noinline__)) +void * +memchr (const void *s, int c, __SIZE_TYPE__ n) +{ + const unsigned char uc = c; + const unsigned char *sp; + +#ifdef __OPTIMIZE__ + if (inside_main) + abort (); +#endif + + sp = s; + for (; n != 0; ++sp, --n) + if (*sp == uc) + return (void *) sp; + + return 0; +} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/memcmp.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/memcmp.c new file mode 100644 index 000000000..fd6556d22 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/memcmp.c @@ -0,0 +1,23 @@ +extern void abort(void); +extern int inside_main; + +__attribute__ ((__noinline__)) +int +memcmp (const void *s1, const void *s2, __SIZE_TYPE__ len) +{ + const unsigned char *sp1, *sp2; + +#ifdef __OPTIMIZE__ + if (inside_main) + abort (); +#endif + + sp1 = s1; + sp2 = s2; + while (len != 0 && *sp1 == *sp2) + sp1++, sp2++, len--; + + if (len == 0) + return 0; + return *sp1 - *sp2; +} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/memmove.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/memmove.c new file mode 100644 index 000000000..08fcd0801 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/memmove.c @@ -0,0 +1,32 @@ +extern void abort (void); +extern int inside_main; + +__attribute__ ((__noinline__)) +void * +memmove (void *dst, const void *src, __SIZE_TYPE__ n) +{ + char *dstp; + const char *srcp; + +#ifdef __OPTIMIZE__ + if (inside_main) + abort (); +#endif + + srcp = src; + dstp = dst; + if (srcp < dstp) + while (n-- != 0) + dstp[n] = srcp[n]; + else + while (n-- != 0) + *dstp++ = *srcp++; + + return dst; +} + +void +bcopy (const void *src, void *dst, __SIZE_TYPE__ n) +{ + memmove (dst, src, n); +} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/mempcpy.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/mempcpy.c new file mode 100644 index 000000000..bc16da536 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/mempcpy.c @@ -0,0 +1,22 @@ +extern void abort (void); +extern int inside_main; + +__attribute__ ((__noinline__)) +void * +mempcpy (void *dst, const void *src, __SIZE_TYPE__ n) +{ + const char *srcp; + char *dstp; + +#ifdef __OPTIMIZE__ + if (inside_main) + abort (); +#endif + + srcp = src; + dstp = dst; + while (n-- != 0) + *dstp++ = *srcp++; + + return dstp; +} 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 000000000..90545abbf --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/memset.c @@ -0,0 +1,20 @@ +extern void abort (void); +extern int inside_main; + +__attribute__ ((__noinline__)) +void * +memset (void *dst, int c, __SIZE_TYPE__ n) +{ + while (n-- != 0) + n[(char *) dst] = c; + + /* Single-byte memsets should be done inline when optimisation + is enabled. Do this after the copy in case we're being called to + initialize bss. */ +#ifdef __OPTIMIZE__ + if (inside_main && n < 2) + abort (); +#endif + + 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 000000000..4be7578d1 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/printf.c @@ -0,0 +1,38 @@ +#include <stdio.h> +#include <stdarg.h> +extern void abort (void); +extern int inside_main; + +__attribute__ ((__noinline__)) +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; +} + + +/* Locking stdio doesn't matter for the purposes of this test. */ +__attribute__ ((__noinline__)) +int +printf_unlocked (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 000000000..3ac447b11 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/sprintf.c @@ -0,0 +1,22 @@ +#include <stdio.h> +#include <stdarg.h> +extern void abort (void); +extern int inside_main; + +__attribute__ ((__noinline__)) +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/stpcpy.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/stpcpy.c new file mode 100644 index 000000000..2c7c8178b --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/stpcpy.c @@ -0,0 +1,18 @@ +extern void abort (void); +extern int inside_main; + +__attribute__ ((__noinline__)) +char * +stpcpy (char *dst, const char *src) +{ +#ifdef __OPTIMIZE__ + if (inside_main) + abort (); +#endif + + while (*src != 0) + *dst++ = *src++; + + *dst = 0; + return dst; +} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strcat.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strcat.c new file mode 100644 index 000000000..d592087a9 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strcat.c @@ -0,0 +1,20 @@ +extern int inside_main; +extern void abort(void); + +__attribute__ ((__noinline__)) +char * +strcat (char *dst, const char *src) +{ + char *p = dst; + +#ifdef __OPTIMIZE__ + if (inside_main) + abort (); +#endif + + while (*p) + p++; + while ((*p++ = *src++)) + ; + return dst; +} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strchr.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strchr.c new file mode 100644 index 000000000..bee3d3203 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strchr.c @@ -0,0 +1,28 @@ +extern void abort (void); +extern int inside_main; + +__attribute__ ((__noinline__)) +char * +strchr (const char *s, int c) +{ +#ifdef __OPTIMIZE__ + if (inside_main) + abort (); +#endif + + for (;;) + { + if (*s == c) + return (char *) s; + if (*s == 0) + return 0; + s++; + } +} + +__attribute__ ((__noinline__)) +char * +index (const char *s, int c) +{ + return strchr (s, c); +} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strcmp.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strcmp.c new file mode 100644 index 000000000..82284546f --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strcmp.c @@ -0,0 +1,19 @@ +extern void abort (void); +extern int inside_main; + +__attribute__ ((__noinline__)) +int +strcmp (const char *s1, const char *s2) +{ +#ifdef __OPTIMIZE__ + if (inside_main) + abort (); +#endif + + while (*s1 != 0 && *s1 == *s2) + s1++, s2++; + + if (*s1 == 0 || *s2 == 0) + return (unsigned char) *s1 - (unsigned char) *s2; + return *s1 - *s2; +} 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 000000000..916446623 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strcpy.c @@ -0,0 +1,15 @@ +extern void abort (void); +extern int inside_main; + +__attribute__ ((__noinline__)) +char * +strcpy (char *d, const char *s) +{ + char *r = d; +#if defined __OPTIMIZE__ && !defined __OPTIMIZE_SIZE__ + 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 000000000..827099637 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strcspn.c @@ -0,0 +1,22 @@ +extern void abort (void); +extern int inside_main; + +__attribute__ ((__noinline__)) +__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/strlen.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strlen.c new file mode 100644 index 000000000..7f81c115b --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strlen.c @@ -0,0 +1,20 @@ +extern void abort (void); +extern int inside_main; + +__attribute__ ((__noinline__)) +__SIZE_TYPE__ +strlen (const char *s) +{ + __SIZE_TYPE__ i; + +#ifdef __OPTIMIZE__ + if (inside_main) + abort (); +#endif + + i = 0; + while (s[i] != 0) + i++; + + return i; +} 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 000000000..7fd334cb4 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strncat.c @@ -0,0 +1,29 @@ +extern void abort(void); +extern int inside_main; + +typedef __SIZE_TYPE__ size_t; + +__attribute__ ((__noinline__)) +char * +strncat (char *s1, const char *s2, size_t n) +{ + char *dest = s1; + char c = '\0'; +#ifdef __OPTIMIZE__ + if (inside_main) + abort(); +#endif + while (*s1) s1++; + c = '\0'; + 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 000000000..7a8eb6fd2 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strncmp.c @@ -0,0 +1,27 @@ +extern void abort (void); +extern int inside_main; + +typedef __SIZE_TYPE__ size_t; + +__attribute__ ((__noinline__)) +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 000000000..a6ec98b05 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strncpy.c @@ -0,0 +1,21 @@ +extern void abort(void); +extern int inside_main; + +typedef __SIZE_TYPE__ size_t; + +__attribute__ ((__noinline__)) +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 000000000..0c049272c --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strpbrk.c @@ -0,0 +1,21 @@ +extern void abort (void); +extern int inside_main; + +__attribute__ ((__noinline__)) +char * +strpbrk(const char *s1, const char *s2) +{ + const char *p; +#ifdef __OPTIMIZE__ + if (inside_main) + abort (); +#endif + while (*s1) + { + for (p = s2; *p; p++) + if (*s1 == *p) + return (char *)s1; + s1++; + } + return 0; +} diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strrchr.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strrchr.c new file mode 100644 index 000000000..9a45af3c8 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strrchr.c @@ -0,0 +1,32 @@ +extern void abort (void); +extern int inside_main; + +__attribute__ ((__noinline__)) +char * +strrchr (const char *s, int c) +{ + __SIZE_TYPE__ i; + +#ifdef __OPTIMIZE__ + if (inside_main) + abort (); +#endif + + i = 0; + while (s[i] != 0) + i++; + + do + if (s[i] == c) + return (char *) s + i; + while (i-- != 0); + + return 0; +} + +__attribute__ ((__noinline__)) +char * +rindex (const char *s, int c) +{ + return strrchr (s, c); +} 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 000000000..622aac6ab --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strspn.c @@ -0,0 +1,25 @@ +extern void abort (void); +extern int inside_main; + +__attribute__ ((__noinline__)) +__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 000000000..7d3544506 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/strstr.c @@ -0,0 +1,29 @@ +extern void abort (void); +extern int inside_main; + +__attribute__ ((__noinline__)) +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 (*q == 0) + return (char *)s1; + } + return 0; +} |