diff options
author | Kaveh R. Ghazi <ghazi@caip.rutgers.edu> | 2000-12-06 13:05:28 +0000 |
---|---|---|
committer | Kaveh Ghazi <ghazi@gcc.gnu.org> | 2000-12-06 13:05:28 +0000 |
commit | a903143d218daf0bd1878e3ab33b3bf817539ab6 (patch) | |
tree | 8042072ed7df0e3d67c2fd02e7f41f0e79f2dc7b /gcc | |
parent | 5fbf4574d48153ef2fa44bd6722091f1be54a4db (diff) | |
download | gcc-a903143d218daf0bd1878e3ab33b3bf817539ab6.zip gcc-a903143d218daf0bd1878e3ab33b3bf817539ab6.tar.gz gcc-a903143d218daf0bd1878e3ab33b3bf817539ab6.tar.bz2 |
stdio-opt-1.c: Add more checks.
* testsuite/gcc.c-torture/execute/stdio-opt-1.c: Add more checks.
* testsuite/gcc.c-torture/execute/stdio-opt-2.c: New test.
From-SVN: r38065
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/testsuite/gcc.c-torture/execute/stdio-opt-1.c | 53 | ||||
-rw-r--r-- | gcc/testsuite/gcc.c-torture/execute/stdio-opt-2.c | 45 |
3 files changed, 92 insertions, 13 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 34ba49e..d3ca7ef 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2000-12-06 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> + + * testsuite/gcc.c-torture/execute/stdio-opt-1.c: Add more checks. + * testsuite/gcc.c-torture/execute/stdio-opt-2.c: New test. + 2000-12-05 Geoffrey Keating <geoffk@redhat.com> * gcc.c-torture/execute/20001203-2.c: New testcase. @@ -33,7 +38,7 @@ * gcc.dg/cpp/assert_trad1.c, assert_trad2.c, assert_trad3.c: New tests. -2000-12-03 Kaveh R. Ghazi <ghazi@teal.rutgers.edu> +2000-12-03 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> * gcc.c-torture/execute/string-opt-11.c: Add more strspn checks. * gcc.c-torture/execute/string-opt-12.c: Add more strcspn checks. 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 aeb7302..6200786 100644 --- a/gcc/testsuite/gcc.c-torture/execute/stdio-opt-1.c +++ b/gcc/testsuite/gcc.c-torture/execute/stdio-opt-1.c @@ -1,28 +1,57 @@ /* Copyright (C) 2000 Free Software Foundation. - When eliminating NOP calls to builtin fputs, ensure that we still - evaluate the stream argument in case it has side effects. + Ensure all expected transformations of builtin fputs occur and that + we honor side effects in the stream argument. + Written by Kaveh R. Ghazi, 10/30/2000. */ #include <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 main() { - FILE *s_array[3] = {stdout, NULL, stdout}, **s_ptr = s_array; + FILE *s_array[] = {stdout, NULL}, **s_ptr = s_array; + const char *const s1 = "hello world"; + + fputs ("", *s_ptr); + fputs ("\n", *s_ptr); + fputs ("bye", *s_ptr); + fputs (s1, *s_ptr); + fputs (s1+5, *s_ptr); + fputs (s1+10, *s_ptr); + fputs (s1+11, *s_ptr); - /* Increment the stream pointer once. */ + /* Check side-effects when transforming fputs -> NOP. */ fputs ("", *s_ptr++); + if (s_ptr != s_array+1 || *s_ptr != 0) + abort(); - /* Increment the stream pointer a second time. */ - s_ptr++; + /* Check side-effects when transforming fputs -> fputc. */ + s_ptr = s_array; + fputs ("\n", *s_ptr++); + if (s_ptr != s_array+1 || *s_ptr != 0) + abort(); - /* If we failed to increment the stream pointer twice, then the - stream passed in here will be NULL and we should crash. */ - fputs ("hello world\n", *s_ptr); - - /* Just in case, If *s_ptr is NULL abort anyway. */ - if (*s_ptr == 0) + /* Check side-effects when transforming fputs -> fwrite. */ + s_ptr = s_array; + fputs ("hello\n", *s_ptr++); + if (s_ptr != s_array+1 || *s_ptr != 0) abort(); 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. */ +static int +fputs(const char *string, FILE *stream) +{ + abort(); +} +#endif diff --git a/gcc/testsuite/gcc.c-torture/execute/stdio-opt-2.c b/gcc/testsuite/gcc.c-torture/execute/stdio-opt-2.c new file mode 100644 index 0000000..b7bfd33 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/stdio-opt-2.c @@ -0,0 +1,45 @@ +/* Copyright (C) 2000 Free Software Foundation. + + Ensure all expected transformations of builtin printf occur and + that we honor side effects in the arguments. + + Written by Kaveh R. Ghazi, 12/4/2000. */ + +extern int printf (const char *, ...); +extern void abort(void); + +int main() +{ + const char *const s1 = "hello world"; + const char *const s2[] = { s1, 0 }, *const*s3; + + printf ("%s\n", "hello"); + printf ("%s\n", *s2); + s3 = s2; + printf ("%s\n", *s3++); + if (s3 != s2+1 || *s3 != 0) + abort(); + + printf ("%c", '\n'); + printf ("%c", **s2); + s3 = s2; + printf ("%c", **s3++); + if (s3 != s2+1 || *s3 != 0) + abort(); + + printf ("\n"); + printf ("hello world\n"); + + 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. */ +static int +printf (const char *string, ...) +{ + abort(); +} +#endif |