Commit a903143d by Kaveh R. Ghazi Committed by Kaveh Ghazi

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
parent 5fbf4574
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.
......
/* 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
/* 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment