From ce94d12f67d02e9772add99f21c1d1abebd82085 Mon Sep 17 00:00:00 2001 From: "Kaveh R. Ghazi" Date: Wed, 27 Dec 2000 15:29:52 +0000 Subject: [PATCH] stdio-opt-1.c: Test __builtin_ style too. * gcc.c-torture/execute/stdio-opt-1.c: Test __builtin_ style too. * gcc.c-torture/execute/stdio-opt-2.c: Likewise. * gcc.c-torture/execute/string-opt-1.c: Likewise. * gcc.c-torture/execute/string-opt-2.c: Likewise. * gcc.c-torture/execute/string-opt-3.c: Likewise. * gcc.c-torture/execute/string-opt-4.c: Likewise. * gcc.c-torture/execute/string-opt-6.c: Likewise. * gcc.c-torture/execute/string-opt-7.c: Likewise. * gcc.c-torture/execute/string-opt-8.c: Likewise. * gcc.c-torture/execute/string-opt-9.c: Likewise. * gcc.c-torture/execute/string-opt-10.c: Likewise. * gcc.c-torture/execute/string-opt-11.c: Likewise. * gcc.c-torture/execute/string-opt-12.c: Likewise. * gcc.c-torture/execute/string-opt-3.c: Test rindex. * gcc.c-torture/execute/string-opt-4.c: Test index. From-SVN: r38497 --- gcc/testsuite/ChangeLog | 19 +++++++++++++ .../gcc.c-torture/execute/stdio-opt-1.c | 5 ++++ .../gcc.c-torture/execute/stdio-opt-2.c | 4 +++ .../gcc.c-torture/execute/string-opt-1.c | 5 ++++ .../gcc.c-torture/execute/string-opt-10.c | 6 +++++ .../gcc.c-torture/execute/string-opt-11.c | 5 ++++ .../gcc.c-torture/execute/string-opt-12.c | 5 ++++ .../gcc.c-torture/execute/string-opt-2.c | 6 +++++ .../gcc.c-torture/execute/string-opt-3.c | 27 +++++++++++++++---- .../gcc.c-torture/execute/string-opt-4.c | 23 ++++++++++++---- .../gcc.c-torture/execute/string-opt-6.c | 7 +++++ .../gcc.c-torture/execute/string-opt-7.c | 6 +++++ .../gcc.c-torture/execute/string-opt-8.c | 5 ++++ .../gcc.c-torture/execute/string-opt-9.c | 6 +++++ 14 files changed, 119 insertions(+), 10 deletions(-) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index af375824f46..524b5b15711 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,22 @@ +2000-12-27 Kaveh R. Ghazi + + * gcc.c-torture/execute/stdio-opt-1.c: Test __builtin_ style too. + * gcc.c-torture/execute/stdio-opt-2.c: Likewise. + * gcc.c-torture/execute/string-opt-1.c: Likewise. + * gcc.c-torture/execute/string-opt-2.c: Likewise. + * gcc.c-torture/execute/string-opt-3.c: Likewise. + * gcc.c-torture/execute/string-opt-4.c: Likewise. + * gcc.c-torture/execute/string-opt-6.c: Likewise. + * gcc.c-torture/execute/string-opt-7.c: Likewise. + * gcc.c-torture/execute/string-opt-8.c: Likewise. + * gcc.c-torture/execute/string-opt-9.c: Likewise. + * gcc.c-torture/execute/string-opt-10.c: Likewise. + * gcc.c-torture/execute/string-opt-11.c: Likewise. + * gcc.c-torture/execute/string-opt-12.c: Likewise. + + * gcc.c-torture/execute/string-opt-3.c: Test rindex. + * gcc.c-torture/execute/string-opt-4.c: Test index. + 2000-12-26 Geoffrey Keating * gcc.c-torture/compile/20001226-1.c: New test. diff --git a/gcc/testsuite/gcc.c-torture/execute/stdio-opt-1.c b/gcc/testsuite/gcc.c-torture/execute/stdio-opt-1.c index 620078648a4..061946fd2af 100644 --- a/gcc/testsuite/gcc.c-torture/execute/stdio-opt-1.c +++ b/gcc/testsuite/gcc.c-torture/execute/stdio-opt-1.c @@ -42,6 +42,11 @@ int main() if (s_ptr != s_array+1 || *s_ptr != 0) abort(); + /* Test at least one instance of the __builtin_ style. We do this + to ensure that it works and that the prototype is correct. */ + s_ptr = s_array; + __builtin_fputs ("", *s_ptr); + return 0; } diff --git a/gcc/testsuite/gcc.c-torture/execute/stdio-opt-2.c b/gcc/testsuite/gcc.c-torture/execute/stdio-opt-2.c index b7bfd33b05d..1e303361a11 100644 --- a/gcc/testsuite/gcc.c-torture/execute/stdio-opt-2.c +++ b/gcc/testsuite/gcc.c-torture/execute/stdio-opt-2.c @@ -30,6 +30,10 @@ int main() printf ("\n"); printf ("hello world\n"); + /* Test at least one instance of the __builtin_ style. We do this + to ensure that it works and that the prototype is correct. */ + __builtin_printf ("%s\n", "hello"); + return 0; } diff --git a/gcc/testsuite/gcc.c-torture/execute/string-opt-1.c b/gcc/testsuite/gcc.c-torture/execute/string-opt-1.c index 058d5943f58..2210a04e297 100644 --- a/gcc/testsuite/gcc.c-torture/execute/string-opt-1.c +++ b/gcc/testsuite/gcc.c-torture/execute/string-opt-1.c @@ -25,6 +25,11 @@ int main() if (strstr (foo + 1, "world") != foo + 6) abort(); + /* Test at least one instance of the __builtin_ style. We do this + to ensure that it works and that the prototype is correct. */ + if (__builtin_strstr (foo + 1, "world") != foo + 6) + abort(); + return 0; } diff --git a/gcc/testsuite/gcc.c-torture/execute/string-opt-10.c b/gcc/testsuite/gcc.c-torture/execute/string-opt-10.c index 3949bb8ae03..e1a271d0aeb 100644 --- a/gcc/testsuite/gcc.c-torture/execute/string-opt-10.c +++ b/gcc/testsuite/gcc.c-torture/execute/string-opt-10.c @@ -63,6 +63,12 @@ int main () || strcmp (dst, "hello world world")) abort(); + /* Test at least one instance of the __builtin_ style. We do this + to ensure that it works and that the prototype is correct. */ + strcpy (dst, s1); + if (__builtin_strncat (dst, "", 100) != dst || strcmp (dst, s1)) + abort(); + return 0; } diff --git a/gcc/testsuite/gcc.c-torture/execute/string-opt-11.c b/gcc/testsuite/gcc.c-torture/execute/string-opt-11.c index b17e4c1027f..cad19c945b2 100644 --- a/gcc/testsuite/gcc.c-torture/execute/string-opt-11.c +++ b/gcc/testsuite/gcc.c-torture/execute/string-opt-11.c @@ -46,6 +46,11 @@ int main () if (strspn ("", ++d2+5) != 0 || d2 != dst+1) abort(); + /* Test at least one instance of the __builtin_ style. We do this + to ensure that it works and that the prototype is correct. */ + if (__builtin_strspn (s1, "hello") != 5) + abort(); + return 0; } diff --git a/gcc/testsuite/gcc.c-torture/execute/string-opt-12.c b/gcc/testsuite/gcc.c-torture/execute/string-opt-12.c index ebe47e5b0e3..b9df9c2d1cb 100644 --- a/gcc/testsuite/gcc.c-torture/execute/string-opt-12.c +++ b/gcc/testsuite/gcc.c-torture/execute/string-opt-12.c @@ -46,6 +46,11 @@ int main () if (strcspn ("", ++d2+5) != 0 || d2 != dst+1) abort(); + /* Test at least one instance of the __builtin_ style. We do this + to ensure that it works and that the prototype is correct. */ + if (__builtin_strcspn (s1, "z") != 11) + abort(); + return 0; } diff --git a/gcc/testsuite/gcc.c-torture/execute/string-opt-2.c b/gcc/testsuite/gcc.c-torture/execute/string-opt-2.c index 29e9af07d91..7b9bcbf873d 100644 --- a/gcc/testsuite/gcc.c-torture/execute/string-opt-2.c +++ b/gcc/testsuite/gcc.c-torture/execute/string-opt-2.c @@ -7,6 +7,7 @@ extern void abort(void); extern char *strpbrk (const char *, const char *); +extern int strcmp (const char *, const char *); void fn (const char *foo, const char *const *bar) { @@ -26,6 +27,11 @@ void fn (const char *foo, const char *const *bar) abort(); if (strpbrk (foo + 6, "o") != foo + 7) abort(); + + /* Test at least one instance of the __builtin_ style. We do this + to ensure that it works and that the prototype is correct. */ + if (__builtin_strpbrk (foo + 6, "o") != foo + 7) + abort(); } int main() diff --git a/gcc/testsuite/gcc.c-torture/execute/string-opt-3.c b/gcc/testsuite/gcc.c-torture/execute/string-opt-3.c index 5f273996d9b..61718f2900f 100644 --- a/gcc/testsuite/gcc.c-torture/execute/string-opt-3.c +++ b/gcc/testsuite/gcc.c-torture/execute/string-opt-3.c @@ -9,6 +9,7 @@ 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"; @@ -67,11 +68,20 @@ int main() abort (); if (x != 8) abort (); - /* For systems which don't have rindex, we test the __builtin_ - version to avoid spurious link failures at -O0. We only need to - test one case since everything is handled in the same code path - as builtin strrchr. */ - if (__builtin_rindex ("hello", 'z') != 0) + /* 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; @@ -80,7 +90,14 @@ int main() 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__ diff --git a/gcc/testsuite/gcc.c-torture/execute/string-opt-4.c b/gcc/testsuite/gcc.c-torture/execute/string-opt-4.c index 77c0950ff7e..d82bb69a2ab 100644 --- a/gcc/testsuite/gcc.c-torture/execute/string-opt-4.c +++ b/gcc/testsuite/gcc.c-torture/execute/string-opt-4.c @@ -7,6 +7,7 @@ extern void abort (void); extern char *strchr (const char *, int); +extern char *index (const char *, int); int main() { @@ -20,11 +21,16 @@ int main() abort (); if (strchr (foo, '\0') != foo + 11) abort (); - /* For systems which don't have index, we test the __builtin_ - version to avoid spurious link failures at -O0. We only need to - test one case since everything is handled in the same code path - as builtin strchr. */ - if (__builtin_index ("hello", 'z') != 0) + /* 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; @@ -33,7 +39,14 @@ int main() 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__ diff --git a/gcc/testsuite/gcc.c-torture/execute/string-opt-6.c b/gcc/testsuite/gcc.c-torture/execute/string-opt-6.c index 781d96f1dcf..efd502f7b83 100644 --- a/gcc/testsuite/gcc.c-torture/execute/string-opt-6.c +++ b/gcc/testsuite/gcc.c-torture/execute/string-opt-6.c @@ -31,6 +31,13 @@ int main() if (memcpy (p + 3, "FGHI", 4) != p + 3 || memcmp (p, "A\0CFGHIj", 9)) abort (); + /* Test at least one instance of the __builtin_ style. We do this + to ensure that it works and that the prototype is correct. */ + if (__builtin_strcpy (p, "abcde") != p || memcmp (p, "abcde", 6)) + abort (); + if (__builtin_memcpy (p, "ABCDE", 6) != p || memcmp (p, "ABCDE", 6)) + abort (); + return 0; } diff --git a/gcc/testsuite/gcc.c-torture/execute/string-opt-7.c b/gcc/testsuite/gcc.c-torture/execute/string-opt-7.c index 105b3dc95ba..144d9f11072 100644 --- a/gcc/testsuite/gcc.c-torture/execute/string-opt-7.c +++ b/gcc/testsuite/gcc.c-torture/execute/string-opt-7.c @@ -56,6 +56,12 @@ int main () if (strncpy (dst, src, 12) != dst || strcmp (dst, src)) abort(); + /* Test at least one instance of the __builtin_ style. We do this + to ensure that it works and that the prototype is correct. */ + memset (dst, 0, sizeof (dst)); + if (__builtin_strncpy (dst, src, 4) != dst || strncmp (dst, src, 4)) + abort(); + return 0; } diff --git a/gcc/testsuite/gcc.c-torture/execute/string-opt-8.c b/gcc/testsuite/gcc.c-torture/execute/string-opt-8.c index 4c3c0d44eed..6a4edb5d641 100644 --- a/gcc/testsuite/gcc.c-torture/execute/string-opt-8.c +++ b/gcc/testsuite/gcc.c-torture/execute/string-opt-8.c @@ -142,6 +142,11 @@ 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; } diff --git a/gcc/testsuite/gcc.c-torture/execute/string-opt-9.c b/gcc/testsuite/gcc.c-torture/execute/string-opt-9.c index c1174d90f2c..ba248a06ad7 100644 --- a/gcc/testsuite/gcc.c-torture/execute/string-opt-9.c +++ b/gcc/testsuite/gcc.c-torture/execute/string-opt-9.c @@ -33,6 +33,12 @@ int main () if (strcat (++d2+5, s1+11) != dst+6 || d2 != dst+1 || strcmp (dst, s1)) abort(); + /* Test at least one instance of the __builtin_ style. We do this + to ensure that it works and that the prototype is correct. */ + strcpy (dst, s1); + if (__builtin_strcat (dst, "") != dst || strcmp (dst, s1)) + abort(); + return 0; }