OSDN Git Service

* testsuite/gcc.c-torture/execute/stdio-opt-1.c: Add more checks.
authorghazi <ghazi@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 6 Dec 2000 13:05:28 +0000 (13:05 +0000)
committerghazi <ghazi@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 6 Dec 2000 13:05:28 +0000 (13:05 +0000)
* testsuite/gcc.c-torture/execute/stdio-opt-2.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@38065 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/stdio-opt-1.c
gcc/testsuite/gcc.c-torture/execute/stdio-opt-2.c [new file with mode: 0644]

index 34ba49e..d3ca7ef 100644 (file)
@@ -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.
index aeb7302..6200786 100644 (file)
@@ -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 (file)
index 0000000..b7bfd33
--- /dev/null
@@ -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