From a903143d218daf0bd1878e3ab33b3bf817539ab6 Mon Sep 17 00:00:00 2001 From: "Kaveh R. Ghazi" Date: Wed, 6 Dec 2000 13:05:28 +0000 Subject: [PATCH] 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 --- gcc/testsuite/ChangeLog | 7 ++- .../gcc.c-torture/execute/stdio-opt-1.c | 53 ++++++++++++++----- .../gcc.c-torture/execute/stdio-opt-2.c | 45 ++++++++++++++++ 3 files changed, 92 insertions(+), 13 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/stdio-opt-2.c diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 34ba49e016b..d3ca7efe2af 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2000-12-06 Kaveh R. Ghazi + + * 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 * 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 +2000-12-03 Kaveh R. Ghazi * 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 aeb7302dc93..620078648a4 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 +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"; - /* Increment the stream pointer once. */ + 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); + + /* 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 00000000000..b7bfd33b05d --- /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