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
This commit is contained in:
parent
5fbf4574d4
commit
a903143d21
@ -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.
|
||||
|
@ -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";
|
||||
|
||||
/* 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
|
||||
|
45
gcc/testsuite/gcc.c-torture/execute/stdio-opt-2.c
Normal file
45
gcc/testsuite/gcc.c-torture/execute/stdio-opt-2.c
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user