* gcc.c-torture/execute/builtins: New directory.
* gcc.c-torture/execute/string-opt-{3,4,16,17,18,19}.c: Move into
gcc.c-torture/execute/builtins.
* gcc.c-torture/execute/string-opt-asm-{1,2}.c: Likewise.
* gcc.c-torture/execute/builtin-noret-{1,2}.c: Move to...
* gcc.dg/torture: ...this new directory. Turn into link-only tests.
* gcc.dg/no-builtin-1.c: Move into gcc.c-torture/execute/builtins.
From-SVN: r66680
+2003-05-11 Richard Sandiford <rsandifo@redhat.com>
+
+ * gcc.c-torture/execute/builtins: New directory.
+ * gcc.c-torture/execute/string-opt-{3,4,16,17,18,19}.c: Move into
+ gcc.c-torture/execute/builtins.
+ * gcc.c-torture/execute/string-opt-asm-{1,2}.c: Likewise.
+ * gcc.c-torture/execute/builtin-noret-{1,2}.c: Move to...
+ * gcc.dg/torture: ...this new directory. Turn into link-only tests.
+ * gcc.dg/no-builtin-1.c: Move into gcc.c-torture/execute/builtins.
+
2003-05-10 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/9252
+++ /dev/null
-/* Test for builtin noreturn attributes. */
-/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
-
-extern void abort (void);
-extern void exit (int);
-extern void _exit (int);
-extern void _Exit (int);
-
-extern void tabort (void);
-extern void texit (void);
-extern void t_exit (void);
-extern void t_Exit (void);
-
-extern void link_failure (void);
-
-int
-main (void)
-{
- volatile int i = 0;
- /* The real test here is that the program links. */
- if (i)
- tabort ();
- if (i)
- texit ();
- if (i)
- t_exit ();
- if (i)
- t_Exit ();
- exit (0);
-}
-
-void
-tabort (void)
-{
- abort ();
- link_failure ();
-}
-
-void
-texit (void)
-{
- exit (1);
- link_failure ();
-}
-
-void
-t_exit (void)
-{
- _exit (1);
- link_failure ();
-}
-
-/* Some non-Unix libcs might not have _exit. This version should never
- get called. */
-static void
-_exit (int i)
-{
- abort ();
-}
-
-void
-t_Exit (void)
-{
- _Exit (1);
- link_failure ();
-}
-
-/* Some libcs might not have _Exit. This version should never get called. */
-static void
-_Exit (int i)
-{
- abort ();
-}
-
-/* When optimizing, no calls to link_failure should remain. In any case,
- link_failure should not be called. */
-
-#ifndef __OPTIMIZE__
-void
-link_failure (void)
-{
- abort ();
-}
-#endif
+++ /dev/null
-/* Test for builtin noreturn attributes when the visible declarations
- are function-local. Doesn't presently work. Modified from
- builtin-noret-1.c by Zack Weinberg <zack@codesourcery.com>. */
-
-extern void tabort (void);
-extern void texit (void);
-extern void t_exit (void);
-extern void t_Exit (void);
-
-extern void link_failure (void);
-
-int
-main (void)
-{
- volatile int i = 0;
- /* The real test here is that the program links. */
- if (i)
- tabort ();
- if (i)
- texit ();
- if (i)
- t_exit ();
- if (i)
- t_Exit ();
- exit (0);
-}
-
-void
-tabort (void)
-{
- extern void abort (void);
- abort ();
- link_failure ();
-}
-
-void
-texit (void)
-{
- extern void exit (int);
- exit (1);
- link_failure ();
-}
-
-void
-t_exit (void)
-{
- extern void _exit (int);
- _exit (1);
- link_failure ();
-}
-
-/* Some non-Unix libcs might not have _exit. This version should never
- get called. */
-static void
-_exit (int i)
-{
- abort ();
-}
-
-void
-t_Exit (void)
-{
- extern void _Exit (int);
- _Exit (1);
- link_failure ();
-}
-
-/* Some libcs might not have _Exit. This version should never get called. */
-static void
-_Exit (int i)
-{
- abort ();
-}
-
-/* When optimizing, no calls to link_failure should remain. In any case,
- link_failure should not be called. */
-
-#ifndef __OPTIMIZE__
-void
-link_failure (void)
-{
- abort ();
-}
-#endif
--- /dev/null
+extern int abs_called;
+extern int inside_main;
+
+/* The labs call should have been optimized, but the abs call
+ shouldn't have been. */
+
+int
+abs (int x)
+{
+ if (inside_main)
+ abs_called = 1;
+ return (x < 0 ? -x : x);
+}
+
+long
+labs (long x)
+{
+ if (inside_main)
+ abort ();
+ return (x < 0 ? -x : x);
+}
--- /dev/null
+/* Test for -fno-builtin-FUNCTION. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk>. */
+/* GCC normally handles abs and labs as built-in functions even without
+ optimization. So test that with -fno-builtin-abs, labs is so handled
+ but abs isn't. */
+
+int abs_called = 0;
+
+extern int abs (int);
+extern long labs (long);
+extern void abort (void);
+extern void exit (int);
+
+void
+main_test (void)
+{
+ if (labs (0) != 0)
+ abort ();
+ if (abs (0) != 0)
+ abort ();
+ if (!abs_called)
+ abort ();
+}
--- /dev/null
+set additional_flags -fno-builtin-abs
+return 0
--- /dev/null
+# This harness is for testing builtin support. Each test has two files:
+#
+# - foo.c defines the main testing function, main_test().
+# - foo-lib.c implements the library functions that foo.c is testing.
+#
+# The functions in foo-lib.c will often want to abort on certain inputs.
+# They can use the global variable inside_main to see whether they are
+# being called from the test program or part of the common runtime.
+#
+# In many cases, the library functions will behave as normal at -O0
+# and abort when optimisation is enabled. Such implementations should
+# go into the lib/ directory so that they can be included by any test
+# that needs them. They shouldn't call any external functions in case
+# those functions were overridden too.
+
+load_lib c-torture.exp
+
+foreach src [lsort [find $srcdir/$subdir *.c]] {
+ if {![string match *-lib.c $src] && [runtest_file_p $runtests $src]} {
+ c-torture-execute [list $src \
+ [file root $src]-lib.c \
+ $srcdir/$subdir/lib/main.c]
+ }
+}
--- /dev/null
+extern void main_test (void);
+int inside_main;
+
+int
+main ()
+{
+ inside_main = 1;
+ main_test ();
+ inside_main = 0;
+ return 0;
+}
--- /dev/null
+extern int inside_main;
+
+int
+memcmp (const void *s1, const void *s2, __SIZE_TYPE__ len)
+{
+ const unsigned char *sp1, *sp2;
+
+#ifdef __OPTIMIZE__
+ if (inside_main)
+ abort ();
+#endif
+
+ sp1 = s1;
+ sp2 = s2;
+ while (len != 0 && *sp1 == *sp2)
+ sp1++, sp2++, len--;
+
+ if (len == 0)
+ return 0;
+ return *sp1 - *sp2;
+}
--- /dev/null
+extern int inside_main;
+
+void *
+memmove (void *dst, const void *src, __SIZE_TYPE__ n)
+{
+ char *dstp;
+ const char *srcp;
+
+#ifdef __OPTIMIZE__
+ if (inside_main)
+ abort ();
+#endif
+
+ srcp = src;
+ dstp = dst;
+ if (srcp < dstp)
+ while (n-- != 0)
+ dstp[n] = srcp[n];
+ else
+ while (n-- != 0)
+ *dstp++ = *srcp++;
+
+ return dst;
+}
+
+void
+bcopy (const void *src, void *dst, __SIZE_TYPE__ n)
+{
+ memmove (dst, src, n);
+}
--- /dev/null
+extern int inside_main;
+
+void *
+mempcpy (void *dst, const void *src, __SIZE_TYPE__ n)
+{
+ const char *srcp;
+ char *dstp;
+
+#ifdef __OPTIMIZE__
+ if (inside_main)
+ abort ();
+#endif
+
+ srcp = src;
+ dstp = dst;
+ while (n-- != 0)
+ *dstp++ = *srcp++;
+
+ return dstp;
+}
--- /dev/null
+extern int inside_main;
+
+char *
+stpcpy (char *dst, const char *src)
+{
+#ifdef __OPTIMIZE__
+ if (inside_main)
+ abort ();
+#endif
+
+ while (*src != 0)
+ *dst++ = *src++;
+
+ *dst = 0;
+ return dst;
+}
--- /dev/null
+extern int inside_main;
+
+char *
+strchr (const char *s, int c)
+{
+#ifdef __OPTIMIZE__
+ if (inside_main)
+ abort ();
+#endif
+
+ for (;;)
+ {
+ if (*s == c)
+ return (char *) s;
+ if (*s == 0)
+ return 0;
+ s++;
+ }
+}
+
+char *
+index (const char *s, int c)
+{
+ return strchr (s, c);
+}
--- /dev/null
+extern int inside_main;
+
+int
+strcmp (const char *s1, const char *s2)
+{
+#ifdef __OPTIMIZE__
+ if (inside_main)
+ abort ();
+#endif
+
+ while (*s1 != 0 && *s1 == *s2)
+ s1++, s2++;
+
+ if (*s1 == 0 || *s2 == 0)
+ return (unsigned char) *s1 - (unsigned char) *s2;
+ return *s1 - *s2;
+}
--- /dev/null
+extern int inside_main;
+
+__SIZE_TYPE__
+strlen (const char *s)
+{
+ __SIZE_TYPE__ i;
+
+#ifdef __OPTIMIZE__
+ if (inside_main)
+ abort ();
+#endif
+
+ i = 0;
+ while (s[i] != 0)
+ i++;
+
+ return i;
+}
--- /dev/null
+extern int inside_main;
+
+char *
+strrchr (const char *s, int c)
+{
+ __SIZE_TYPE__ i;
+
+#ifdef __OPTIMIZE__
+ if (inside_main)
+ abort ();
+#endif
+
+ i = 0;
+ while (s[i] != 0)
+ i++;
+
+ do
+ if (s[i] == c)
+ return (char *) s + i;
+ while (i-- != 0);
+
+ return 0;
+}
+
+char *
+rindex (const char *s, int c)
+{
+ return strrchr (s, c);
+}
--- /dev/null
+#include "lib/strrchr.c"
+#include "lib/strlen.c"
+#include "lib/strcmp.c"
--- /dev/null
+/* Copyright (C) 2000, 2003 Free Software Foundation.
+
+ Ensure all expected transformations of builtin strlen, strcmp,
+ strrchr and rindex occur and perform correctly.
+
+ Written by Jakub Jelinek, 11/7/2000. */
+
+extern void abort (void);
+extern __SIZE_TYPE__ strlen (const char *);
+extern int strcmp (const char *, const char *);
+extern char *strrchr (const char *, int);
+extern char *rindex (const char *, int);
+
+int x = 6;
+char *bar = "hi world";
+
+void
+main_test (void)
+{
+ const char *const foo = "hello world";
+
+ if (strlen (foo) != 11)
+ abort ();
+ if (strlen (foo + 4) != 7)
+ abort ();
+ if (strlen (foo + (x++ & 7)) != 5)
+ abort ();
+ if (x != 7)
+ abort ();
+ if (strcmp (foo, "hello") <= 0)
+ abort ();
+ if (strcmp (foo + 2, "llo") <= 0)
+ abort ();
+ if (strcmp (foo, foo) != 0)
+ abort ();
+ if (strcmp (foo, "hello world ") >= 0)
+ abort ();
+ if (strcmp (foo + 10, "dx") >= 0)
+ abort ();
+ if (strcmp (10 + foo, "dx") >= 0)
+ abort ();
+ if (strcmp (bar, "") <= 0)
+ abort ();
+ if (strcmp ("", bar) >= 0)
+ abort ();
+ if (strcmp (bar+8, "") != 0)
+ abort ();
+ if (strcmp ("", bar+8) != 0)
+ abort ();
+ if (strcmp (bar+(--x), "") <= 0 || x != 6)
+ abort ();
+ if (strcmp ("", bar+(++x)) >= 0 || x != 7)
+ abort ();
+ if (strrchr (foo, 'x'))
+ abort ();
+ if (strrchr (foo, 'o') != foo + 7)
+ abort ();
+ if (strrchr (foo, 'e') != foo + 1)
+ abort ();
+ if (strrchr (foo + 3, 'e'))
+ abort ();
+ if (strrchr (foo, '\0') != foo + 11)
+ abort ();
+ if (strrchr (bar, '\0') != bar + 8)
+ abort ();
+ if (strrchr (bar + 4, '\0') != bar + 8)
+ abort ();
+ if (strrchr (bar + (x++ & 3), '\0') != bar + 8)
+ abort ();
+ if (x != 8)
+ abort ();
+ /* Test only one instance of rindex since the code path is the same
+ as that of strrchr. */
+ if (rindex ("hello", 'z') != 0)
+ abort ();
+
+ /* Test at least one instance of the __builtin_ style. We do this
+ to ensure that it works and that the prototype is correct. */
+ if (__builtin_rindex (foo, 'o') != foo + 7)
+ abort ();
+ if (__builtin_strrchr (foo, 'o') != foo + 7)
+ abort ();
+ if (__builtin_strlen (foo) != 11)
+ abort ();
+ if (__builtin_strcmp (foo, "hello") <= 0)
+ abort ();
+}
--- /dev/null
+#include "lib/strchr.c"
--- /dev/null
+/* Copyright (C) 2000, 2003 Free Software Foundation.
+
+ Ensure all expected transformations of builtin strchr and index
+ occur and perform correctly.
+
+ Written by Jakub Jelinek, 11/7/2000. */
+
+extern void abort (void);
+extern char *strchr (const char *, int);
+extern char *index (const char *, int);
+
+void
+main_test (void)
+{
+ const char *const foo = "hello world";
+
+ if (strchr (foo, 'x'))
+ abort ();
+ if (strchr (foo, 'o') != foo + 4)
+ abort ();
+ if (strchr (foo + 5, 'o') != foo + 7)
+ abort ();
+ if (strchr (foo, '\0') != foo + 11)
+ abort ();
+ /* Test only one instance of index since the code path is the same
+ as that of strchr. */
+ if (index ("hello", 'z') != 0)
+ abort ();
+
+ /* Test at least one instance of the __builtin_ style. We do this
+ to ensure that it works and that the prototype is correct. */
+ if (__builtin_strchr (foo, 'o') != foo + 4)
+ abort ();
+ if (__builtin_index (foo, 'o') != foo + 4)
+ abort ();
+}
--- /dev/null
+extern int inside_main;
+
+void *
+memset (void *dst, int c, __SIZE_TYPE__ n)
+{
+ /* Single-byte memsets should be done inline when optimisation
+ is enabled. */
+#ifdef __OPTIMIZE__
+ if (inside_main && n < 2)
+ abort ();
+#endif
+
+ while (n-- != 0)
+ n[(char *) dst] = c;
+
+ return dst;
+}
--- /dev/null
+/* Copyright (C) 2002, 2003 Free Software Foundation.
+
+ Ensure that builtin memset operations for constant length and
+ non-constant assigned value don't cause compiler problems.
+
+ Written by Roger Sayle, 21 April 2002. */
+
+extern void abort (void);
+typedef __SIZE_TYPE__ size_t;
+extern void *memset (void *, int, size_t);
+
+char buffer[32];
+int argc = 1;
+
+void
+main_test (void)
+{
+ memset (buffer, argc, 0);
+ memset (buffer, argc, 1);
+ memset (buffer, argc, 2);
+ memset (buffer, argc, 3);
+ memset (buffer, argc, 4);
+ memset (buffer, argc, 5);
+ memset (buffer, argc, 6);
+ memset (buffer, argc, 7);
+ memset (buffer, argc, 8);
+ memset (buffer, argc, 9);
+ memset (buffer, argc, 10);
+ memset (buffer, argc, 11);
+ memset (buffer, argc, 12);
+ memset (buffer, argc, 13);
+ memset (buffer, argc, 14);
+ memset (buffer, argc, 15);
+ memset (buffer, argc, 16);
+ memset (buffer, argc, 17);
+}
--- /dev/null
+#include "lib/stpcpy.c"
+#include "lib/mempcpy.c"
--- /dev/null
+/* Copyright (C) 2003 Free Software Foundation.
+
+ Ensure builtin mempcpy and stpcpy perform correctly.
+
+ Written by Kaveh Ghazi, 4/11/2003. */
+
+extern void abort (void);
+extern char *strcpy (char *, const char *);
+extern char *stpcpy (char *, const char *);
+typedef __SIZE_TYPE__ size_t;
+extern size_t strlen(const char *);
+extern void *memcpy (void *, const void *, size_t);
+extern void *mempcpy (void *, const void *, size_t);
+extern int memcmp (const void *, const void *, size_t);
+
+const char s1[] = "123";
+char p[32] = "";
+char *s2 = "defg";
+char *s3 = "FGH";
+size_t l1 = 1;
+
+void
+main_test (void)
+{
+ int i;
+ const char *s;
+
+ if (stpcpy (p, "abcde") != p + 5 || memcmp (p, "abcde", 6))
+ abort ();
+ if (stpcpy (p + 16, "vwxyz" + 1) != p + 16 + 4 || memcmp (p + 16, "wxyz", 5))
+ abort ();
+ if (stpcpy (p + 1, "") != p + 1 + 0 || memcmp (p, "a\0cde", 6))
+ abort ();
+ if (stpcpy (p + 3, "fghij") != p + 3 + 5 || memcmp (p, "a\0cfghij", 9))
+ abort ();
+ if (mempcpy (p, "ABCDE", 6) != p + 6 || memcmp (p, "ABCDE", 6))
+ abort ();
+ if (mempcpy (p + 16, "VWX" + 1, 2) != p + 16 + 2 || memcmp (p + 16, "WXyz", 5))
+ abort ();
+ if (mempcpy (p + 1, "", 1) != p + 1 + 1 || memcmp (p, "A\0CDE", 6))
+ abort ();
+ if (mempcpy (p + 3, "FGHI", 4) != p + 3 + 4 || memcmp (p, "A\0CFGHIj", 9))
+ abort ();
+
+ i = 8;
+ memcpy (p + 20, "qrstu", 6);
+ if (stpcpy ((i++, p + 20 + 1), "23") != (p + 20 + 1 + 2) || i != 9 || memcmp (p + 20, "q23\0u", 6))
+ abort ();
+
+ s = s1; i = 3;
+ memcpy (p + 25, "QRSTU", 6);
+ if (mempcpy (p + 25 + 1, s++, i++) != (p + 25 + 1 + 3) || i != 4 || s != s1 + 1 || memcmp (p + 25, "Q123U", 6))
+ abort ();
+
+ if (stpcpy (stpcpy (p, "ABCD"), "EFG") != p + 7 || memcmp (p, "ABCDEFG", 8))
+ abort();
+ if (mempcpy (mempcpy (p, "abcdEFG", 4), "efg", 4) != p + 8 || memcmp (p, "abcdefg", 8))
+ abort();
+
+ /* Test at least one instance of the __builtin_ style. We do this
+ to ensure that it works and that the prototype is correct. */
+ if (__builtin_stpcpy (p, "abcde") != p + 5 || memcmp (p, "abcde", 6))
+ abort ();
+ if (__builtin_mempcpy (p, "ABCDE", 6) != p + 6 || memcmp (p, "ABCDE", 6))
+ abort ();
+
+ /* If the result of stpcpy/mempcpy is ignored, gcc should use
+ strcpy/memcpy. */
+ stpcpy (p + 3, s2);
+ if (memcmp (p, "ABCdefg", 8))
+ abort ();
+ mempcpy (p + 5, s3, 1);
+ if (memcmp (p, "ABCdeFg", 8))
+ abort ();
+ mempcpy (p + 6, s3 + 1, l1);
+ if (memcmp (p, "ABCdeFG", 8))
+ abort ();
+}
--- /dev/null
+#include "lib/memmove.c"
--- /dev/null
+/* Copyright (C) 2003 Free Software Foundation.
+
+ Ensure builtin memmove and bcopy perform correctly.
+
+ Written by Jakub Jelinek, 4/26/2003. */
+
+extern void abort (void);
+typedef __SIZE_TYPE__ size_t;
+extern void *memmove (void *, const void *, size_t);
+extern void bcopy (const void *, void *, size_t);
+extern int memcmp (const void *, const void *, size_t);
+
+const char s1[] = "123";
+char p[32] = "";
+
+static const struct foo
+{
+ char *s;
+ double d;
+ long l;
+} foo[] =
+{
+ { "hello world1", 3.14159, 101L },
+ { "hello world2", 3.14159, 102L },
+ { "hello world3", 3.14159, 103L },
+ { "hello world4", 3.14159, 104L },
+ { "hello world5", 3.14159, 105L },
+ { "hello world6", 3.14159, 106L }
+};
+
+static const struct bar
+{
+ char *s;
+ const struct foo f[3];
+} bar[] =
+{
+ {
+ "hello world10",
+ {
+ { "hello1", 3.14159, 201L },
+ { "hello2", 3.14159, 202L },
+ { "hello3", 3.14159, 203L },
+ }
+ },
+ {
+ "hello world11",
+ {
+ { "hello4", 3.14159, 204L },
+ { "hello5", 3.14159, 205L },
+ { "hello6", 3.14159, 206L },
+ }
+ }
+};
+
+static const int baz[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
+
+void
+main_test (void)
+{
+ const char *s;
+ struct foo f1[sizeof foo/sizeof*foo];
+ struct bar b1[sizeof bar/sizeof*bar];
+ int bz[sizeof baz/sizeof*baz];
+
+ if (memmove (f1, foo, sizeof (foo)) != f1 || memcmp (f1, foo, sizeof(foo)))
+ abort();
+ if (memmove (b1, bar, sizeof (bar)) != b1 || memcmp (b1, bar, sizeof(bar)))
+ abort();
+ bcopy (baz, bz, sizeof (baz));
+ if (memcmp (bz, baz, sizeof(baz)))
+ abort();
+
+ if (memmove (p, "abcde", 6) != p || memcmp (p, "abcde", 6))
+ abort ();
+ s = s1;
+ if (memmove (p + 2, ++s, 0) != p + 2 || memcmp (p, "abcde", 6) || s != s1 + 1)
+ abort ();
+ if (__builtin_memmove (p + 3, "", 1) != p + 3 || memcmp (p, "abc\0e", 6))
+ abort ();
+ bcopy ("fghijk", p + 2, 4);
+ if (memcmp (p, "abfghi", 7))
+ abort ();
+ s = s1 + 1;
+ bcopy (s++, p + 1, 0);
+ if (memcmp (p, "abfghi", 7) || s != s1 + 2)
+ abort ();
+ __builtin_bcopy ("ABCDE", p + 4, 1);
+ if (memcmp (p, "abfgAi", 7))
+ abort ();
+}
--- /dev/null
+#include "lib/memcmp.c"
--- /dev/null
+/* Copyright (C) 2001 Free Software Foundation.
+
+ Ensure that builtin memcmp operations when all three arguments
+ are constant is optimized and performs correctly. Taken from
+ PR optimize/3508.
+
+ Written by Roger Sayle, 12/26/2001. */
+
+extern void abort (void);
+extern void link_error (void);
+
+typedef __SIZE_TYPE__ size_t;
+extern int memcmp (const void *, const void *, size_t);
+
+void
+main_test (void)
+{
+ if (memcmp ("abcd", "efgh", 4) >= 0)
+ link_error ();
+ if (memcmp ("abcd", "abcd", 4) != 0)
+ link_error ();
+ if (memcmp ("efgh", "abcd", 4) <= 0)
+ link_error ();
+}
+
+#ifndef __OPTIMIZE__
+/* When not optimizing, the above tests may generate references to
+ the function link_error, but should never actually call it. */
+void
+link_error ()
+{
+ abort ();
+}
+#endif
--- /dev/null
+extern int inside_main;
+extern const char *p;
+
+char *
+my_strstr (const char *s1, const char *s2)
+{
+ __SIZE_TYPE__ len = strlen (s2);
+
+#ifdef __OPTIMIZE__
+ /* If optimizing, we should be called only in the strstr (foo + 2, p)
+ case. All other cases should be optimized. */
+ if (inside_main)
+ if (s2 != p || strcmp (s1, "hello world" + 2) != 0)
+ abort ();
+#endif
+ if (len == 0)
+ return (char *) s1;
+ for (s1 = strchr (s1, *s2); s1; s1 = strchr (s1 + 1, *s2))
+ if (strncmp (s1, s2, len) == 0)
+ return (char *) s1;
+ return (char *) 0;
+}
+
+char *
+strstr (const char *s1, const char *s2)
+{
+ if (inside_main)
+ abort ();
+
+ return my_strstr (s1, s2);
+}
--- /dev/null
+/* Copyright (C) 2000, 2003 Free Software Foundation.
+
+ Ensure all expected transformations of builtin strstr occur and
+ perform correctly in presence of redirect. */
+
+typedef __SIZE_TYPE__ size_t;
+extern void abort (void);
+extern char *strstr (const char *, const char *)
+ __asm ("my_strstr");
+
+const char *p = "rld", *q = "hello world";
+
+void
+main_test (void)
+{
+ const char *const foo = "hello world";
+
+ if (strstr (foo, "") != foo)
+ abort ();
+ if (strstr (foo + 4, "") != foo + 4)
+ abort ();
+ if (strstr (foo, "h") != foo)
+ abort ();
+ if (strstr (foo, "w") != foo + 6)
+ abort ();
+ if (strstr (foo + 6, "o") != foo + 7)
+ abort ();
+ if (strstr (foo + 1, "world") != foo + 6)
+ abort ();
+ if (strstr (foo + 2, p) != foo + 8)
+ abort ();
+ if (strstr (q, "") != q)
+ abort ();
+ if (strstr (q + 1, "o") != q + 4)
+ abort ();
+
+ /* Test at least one instance of the __builtin_ style. We do this
+ to ensure that it works and that the prototype is correct. */
+ if (__builtin_strstr (foo + 1, "world") != foo + 6)
+ abort ();
+}
--- /dev/null
+extern int inside_main;
+typedef __SIZE_TYPE__ size_t;
+
+#define TEST_ABORT if (inside_main) abort()
+
+void *
+my_memcpy (void *d, const void *s, size_t n)
+{
+ char *dst = (char *) d;
+ const char *src = (const char *) s;
+ while (n--)
+ *dst++ = *src++;
+ return (char *) d;
+}
+
+void
+my_bcopy (const void *s, void *d, size_t n)
+{
+ char *dst = (char *) d;
+ const char *src = (const char *) s;
+ if (src >= dst)
+ while (n--)
+ *dst++ = *src++;
+ else
+ {
+ dst += n;
+ src += n;
+ while (n--)
+ *--dst = *--src;
+ }
+}
+
+void *
+my_memset (void *d, int c, size_t n)
+{
+ char *dst = (char *) d;
+ while (n--)
+ *dst++ = c;
+ return (char *) d;
+}
+
+void
+my_bzero (void *d, size_t n)
+{
+ char *dst = (char *) d;
+ while (n--)
+ *dst++ = '\0';
+}
+
+void *
+memcpy (void *d, const void *s, size_t n)
+{
+ TEST_ABORT;
+ return my_memcpy (d, s, n);
+}
+
+void
+bcopy (const void *s, void *d, size_t n)
+{
+ TEST_ABORT;
+ my_bcopy (s, d, n);
+}
+
+void *
+memset (void *d, int c, size_t n)
+{
+ TEST_ABORT;
+ return my_memset (d, c, n);
+}
+
+void
+bzero (void *d, size_t n)
+{
+ TEST_ABORT;
+ my_bzero (d, n);
+}
--- /dev/null
+/* Copyright (C) 2003 Free Software Foundation.
+
+ Test memcpy and memset in presence of redirect. */
+
+typedef __SIZE_TYPE__ size_t;
+extern void abort (void);
+extern void *memcpy (void *, const void *, size_t)
+ __asm ("my_memcpy");
+extern void bcopy (const void *, void *, size_t)
+ __asm ("my_bcopy");
+extern void *memset (void *, int, size_t)
+ __asm ("my_memset");
+extern void bzero (void *, size_t)
+ __asm ("my_bzero");
+extern int memcmp (const void *, const void *, size_t);
+
+struct A { char c[32]; } a = { "foobar" };
+char x[64] = "foobar", y[64];
+int i = 39, j = 6, k = 4;
+
+void
+main_test (void)
+{
+ struct A b = a;
+ struct A c = { { 'x' } };
+
+ if (memcmp (b.c, x, 32) || c.c[0] != 'x' || memcmp (c.c + 1, x + 32, 31))
+ abort ();
+ if (__builtin_memcpy (y, x, i) != y || memcmp (x, y, 64))
+ abort ();
+ if (memcpy (y + 6, x, j) != y + 6
+ || memcmp (x, y, 6) || memcmp (x, y + 6, 58))
+ abort ();
+ if (__builtin_memset (y + 2, 'X', k) != y + 2
+ || memcmp (y, "foXXXXfoobar", 13))
+ abort ();
+ bcopy (y + 1, y + 2, 6);
+ if (memcmp (y, "fooXXXXfobar", 13))
+ abort ();
+ __builtin_bzero (y + 4, 2);
+ if (memcmp (y, "fooX\0\0Xfobar", 13))
+ abort ();
+}
+++ /dev/null
-/* 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);
-
-int
-main (int argc)
-{
- if (memcmp ("abcd", "efgh", 4) >= 0)
- link_error ();
- if (memcmp ("abcd", "abcd", 4) != 0)
- link_error ();
- if (memcmp ("efgh", "abcd", 4) <= 0)
- link_error ();
- 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 *s1, const void *s2, size_t len)
-{
- abort ();
-}
-#else
-/* When not optimizing, the above tests may generate references to
- the function link_error, but should never actually call it. */
-__attribute__ ((noinline))
-static void
-link_error ()
-{
- abort ();
-}
-#endif
-
+++ /dev/null
-/* Copyright (C) 2002 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
-main (int argc)
-{
- 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);
-
- return 0;
-}
-
-#ifdef __OPTIMIZE__
-/* When optimizing, most of the above cases should be transformed into
- something else. So any remaining calls to the original function
- for short lengths should abort. */
-__attribute__ ((noinline))
-static void *
-memset (void *dst, int c, size_t len)
-{
- if (len < 2)
- abort ();
-}
-#endif
-
+++ /dev/null
-/* Copyright (C) 2003 Free Software Foundation.
-
- Ensure builtin mempcpy and stpcpy perform correctly.
-
- Written by Kaveh Ghazi, 4/11/2003. */
-
-extern void abort (void);
-extern char *strcpy (char *, const char *);
-extern char *stpcpy (char *, const char *);
-typedef __SIZE_TYPE__ size_t;
-extern size_t strlen(const char *);
-extern void *memcpy (void *, const void *, size_t);
-extern void *mempcpy (void *, const void *, size_t);
-extern int memcmp (const void *, const void *, size_t);
-
-const char s1[] = "123";
-char p[32] = "";
-char *s2 = "defg";
-char *s3 = "FGH";
-size_t l1 = 1;
-
-int main()
-{
- int i;
- const char *s;
-
- if (stpcpy (p, "abcde") != p + 5 || memcmp (p, "abcde", 6))
- abort ();
- if (stpcpy (p + 16, "vwxyz" + 1) != p + 16 + 4 || memcmp (p + 16, "wxyz", 5))
- abort ();
- if (stpcpy (p + 1, "") != p + 1 + 0 || memcmp (p, "a\0cde", 6))
- abort ();
- if (stpcpy (p + 3, "fghij") != p + 3 + 5 || memcmp (p, "a\0cfghij", 9))
- abort ();
- if (mempcpy (p, "ABCDE", 6) != p + 6 || memcmp (p, "ABCDE", 6))
- abort ();
- if (mempcpy (p + 16, "VWX" + 1, 2) != p + 16 + 2 || memcmp (p + 16, "WXyz", 5))
- abort ();
- if (mempcpy (p + 1, "", 1) != p + 1 + 1 || memcmp (p, "A\0CDE", 6))
- abort ();
- if (mempcpy (p + 3, "FGHI", 4) != p + 3 + 4 || memcmp (p, "A\0CFGHIj", 9))
- abort ();
-
- i = 8;
- memcpy (p + 20, "qrstu", 6);
- if (stpcpy ((i++, p + 20 + 1), "23") != (p + 20 + 1 + 2) || i != 9 || memcmp (p + 20, "q23\0u", 6))
- abort ();
-
- s = s1; i = 3;
- memcpy (p + 25, "QRSTU", 6);
- if (mempcpy (p + 25 + 1, s++, i++) != (p + 25 + 1 + 3) || i != 4 || s != s1 + 1 || memcmp (p + 25, "Q123U", 6))
- abort ();
-
- if (stpcpy (stpcpy (p, "ABCD"), "EFG") != p + 7 || memcmp (p, "ABCDEFG", 8))
- abort();
- if (mempcpy (mempcpy (p, "abcdEFG", 4), "efg", 4) != p + 8 || memcmp (p, "abcdefg", 8))
- abort();
-
- /* Test at least one instance of the __builtin_ style. We do this
- to ensure that it works and that the prototype is correct. */
- if (__builtin_stpcpy (p, "abcde") != p + 5 || memcmp (p, "abcde", 6))
- abort ();
- if (__builtin_mempcpy (p, "ABCDE", 6) != p + 6 || memcmp (p, "ABCDE", 6))
- abort ();
-
- /* If the result of stpcpy/mempcpy is ignored, gcc should use
- strcpy/memcpy. */
- stpcpy (p + 3, s2);
- if (memcmp (p, "ABCdefg", 8))
- abort ();
- mempcpy (p + 5, s3, 1);
- if (memcmp (p, "ABCdeFg", 8))
- abort ();
- mempcpy (p + 6, s3 + 1, l1);
- if (memcmp (p, "ABCdeFG", 8))
- abort ();
- return 0;
-}
-
-/* When optimizing, all the above cases should be transformed into
- something else. So any remaining calls to the original function
- should abort. When not optimizing, we provide fallback funcs for
- platforms that don't have mempcpy or stpcpy in libc.*/
-__attribute__ ((noinline))
-static char *
-stpcpy (char *d, const char *s)
-{
-#ifdef __OPTIMIZE__
- abort ();
-#else
- return strcpy (d, s) + strlen (s);
-#endif
-}
-
-__attribute__ ((noinline))
-static void *
-mempcpy (void *dst, const void *src, size_t sz)
-{
-#ifdef __OPTIMIZE__
- abort ();
-#else
- return (char *) memcpy (dst, src, sz) + sz;
-#endif
-}
+++ /dev/null
-/* 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 };
-
-int main()
-{
- 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 ();
-
- return 0;
-}
-
-/* When optimizing, all the above cases should be transformed into
- something else. So any remaining calls to the original function
- should abort. When not optimizing, provide memmove/bcopy implementation
- just in case target lacks these in its libc. */
-__attribute__ ((noinline))
-static void *
-memmove (void *d, const void *s, size_t n)
-{
-#ifdef __OPTIMIZE__
- abort ();
-#else
- char *dst = (char *) d;
- const char *src = (const char *) s;
- if (src < dst)
- {
- dst += n;
- src += n;
- while (n--)
- *--dst = *--src;
- }
- else
- while (n--)
- *dst++ = *src++;
- return (char *) d;
-#endif
-}
-
-__attribute__ ((noinline))
-static void
-bcopy (const void *s, void *d, size_t n)
-{
- memmove (d, s, n);
-}
+++ /dev/null
-/* Copyright (C) 2000 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";
-
-int main()
-{
- 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 ();
-
- return 0;
-}
-
-static char *
-rindex (const char *s, int c)
-{
- /* For systems which don't have rindex, we ensure no link failures
- occur by always providing a backup definition. During
- optimization this function aborts to catch errors. */
-#ifdef __OPTIMIZE__
- abort ();
-#else
- return strrchr(s, c);
-#endif
-}
-
-#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_TYPE__
-strlen (const char *s)
-{
- abort ();
-}
-
-__attribute__ ((noinline))
-static int
-strcmp (const char *s1, const char *s2)
-{
- abort ();
-}
-
-__attribute__ ((noinline))
-static char *
-strrchr (const char *s, int c)
-{
- abort ();
-}
-#endif
+++ /dev/null
-/* Copyright (C) 2000 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);
-
-int main()
-{
- 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 ();
-
- return 0;
-}
-
-static char *
-index (const char *s, int c)
-{
- /* For systems which don't have index, we ensure no link failures
- occur by always providing a backup definition. During
- optimization this function aborts to catch errors. */
-#ifdef __OPTIMIZE__
- abort ();
-#else
- return strchr(s, c);
-#endif
-}
-
-#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 *
-strchr (const char *s, int c)
-{
- abort ();
-}
-#endif
+++ /dev/null
-/* Test for -fno-builtin-FUNCTION. */
-/* Origin: Joseph Myers <jsm28@cam.ac.uk>. */
-/* { dg-do run } */
-/* { dg-options "-fno-builtin-abs" } */
-
-/* GCC normally handles abs and labs as built-in functions even without
- optimization. So test that with -fno-builtin-abs, labs is so handled
- but abs isn't. */
-
-int abs_called = 0;
-
-extern int abs (int);
-extern long labs (long);
-extern void abort (void);
-extern void exit (int);
-
-int
-main (void)
-{
- if (labs (0) != 0)
- abort ();
- if (abs (0) != 0)
- abort ();
- if (!abs_called)
- abort ();
- exit (0);
-}
-
-/* The labs call above should have been optimized, but the abs call
- shouldn't have been. */
-
-static int
-abs (int x)
-{ /* { dg-warning "static" "static decl warning" } */
- abs_called = 1;
- return (x < 0 ? -1 : x);
-}
-
-static long
-labs (long x)
-{
- abort ();
-}
--- /dev/null
+/* Test for builtin noreturn attributes. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do link } */
+
+extern void abort (void);
+extern void exit (int);
+extern void _exit (int);
+extern void _Exit (int);
+
+extern void tabort (void);
+extern void texit (void);
+extern void t_exit (void);
+extern void t_Exit (void);
+
+extern void link_failure (void);
+
+int
+main (void)
+{
+ volatile int i = 0;
+ if (i)
+ tabort ();
+ if (i)
+ texit ();
+ if (i)
+ t_exit ();
+ if (i)
+ t_Exit ();
+ exit (0);
+}
+
+void
+tabort (void)
+{
+ abort ();
+ link_failure ();
+}
+
+void
+texit (void)
+{
+ exit (1);
+ link_failure ();
+}
+
+void
+t_exit (void)
+{
+ _exit (1);
+ link_failure ();
+}
+
+/* Some non-Unix libcs might not have _exit. */
+void
+_exit (int i)
+{
+ abort ();
+}
+
+void
+t_Exit (void)
+{
+ _Exit (1);
+ link_failure ();
+}
+
+/* Some libcs might not have _Exit. */
+void
+_Exit (int i)
+{
+ abort ();
+}
--- /dev/null
+/* Test for builtin noreturn attributes when the visible declarations
+ are function-local. Modified from builtin-noret-1.c by Zack Weinberg
+ <zack@codesourcery.com>. */
+/* { dg-do link } */
+
+extern void tabort (void);
+extern void texit (void);
+extern void t_exit (void);
+extern void t_Exit (void);
+
+extern void link_failure (void);
+
+int
+main (void)
+{
+ volatile int i = 0;
+ if (i)
+ tabort ();
+ if (i)
+ texit ();
+ if (i)
+ t_exit ();
+ if (i)
+ t_Exit ();
+ exit (0);
+}
+
+void
+tabort (void)
+{
+ extern void abort (void);
+ abort ();
+ link_failure ();
+}
+
+void
+texit (void)
+{
+ extern void exit (int);
+ exit (1);
+ link_failure ();
+}
+
+void
+t_exit (void)
+{
+ extern void _exit (int);
+ _exit (1);
+ link_failure ();
+}
+
+/* Some non-Unix libcs might not have _exit. */
+void
+_exit (int i)
+{
+ abort ();
+}
+
+void
+t_Exit (void)
+{
+ extern void _Exit (int);
+ _Exit (1);
+ link_failure ();
+}
+
+/* Some libcs might not have _Exit. */
+void
+_Exit (int i)
+{
+ abort ();
+}
--- /dev/null
+# This harness is for tests that should be run at all optimisation levels.
+
+load_lib gcc-dg.exp
+
+dg-init
+gcc-dg-runtest [lsort [glob $srcdir/$subdir/*.c]] ""
+dg-finish