* gcc.c-torture/execute/stdio-opt-1.c: Test __builtin_ style too.
[official-gcc.git] / gcc / testsuite / gcc.c-torture / execute / stdio-opt-1.c
blob061946fd2af684b43099c49c7b866e866d81f4d7
1 /* Copyright (C) 2000 Free Software Foundation.
3 Ensure all expected transformations of builtin fputs occur and that
4 we honor side effects in the stream argument.
6 Written by Kaveh R. Ghazi, 10/30/2000. */
8 #include <stdio.h>
9 extern void abort(void);
10 /* Declare this without args because that's what gcc does internally.
11 We want to make sure it works without a helpful prototype from us.
12 If stdio.h provides one, that is okay. */
13 extern int fputs();
15 int main()
17 FILE *s_array[] = {stdout, NULL}, **s_ptr = s_array;
18 const char *const s1 = "hello world";
20 fputs ("", *s_ptr);
21 fputs ("\n", *s_ptr);
22 fputs ("bye", *s_ptr);
23 fputs (s1, *s_ptr);
24 fputs (s1+5, *s_ptr);
25 fputs (s1+10, *s_ptr);
26 fputs (s1+11, *s_ptr);
28 /* Check side-effects when transforming fputs -> NOP. */
29 fputs ("", *s_ptr++);
30 if (s_ptr != s_array+1 || *s_ptr != 0)
31 abort();
33 /* Check side-effects when transforming fputs -> fputc. */
34 s_ptr = s_array;
35 fputs ("\n", *s_ptr++);
36 if (s_ptr != s_array+1 || *s_ptr != 0)
37 abort();
39 /* Check side-effects when transforming fputs -> fwrite. */
40 s_ptr = s_array;
41 fputs ("hello\n", *s_ptr++);
42 if (s_ptr != s_array+1 || *s_ptr != 0)
43 abort();
45 /* Test at least one instance of the __builtin_ style. We do this
46 to ensure that it works and that the prototype is correct. */
47 s_ptr = s_array;
48 __builtin_fputs ("", *s_ptr);
50 return 0;
53 #ifdef __OPTIMIZE__
54 /* When optimizing, all the above cases should be transformed into
55 something else. So any remaining calls to the original function
56 should abort. */
57 static int
58 fputs(const char *string, FILE *stream)
60 abort();
62 #endif