1 /* Copyright (C) 2000, 2001 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. */
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. */
19 FILE *s_array
[] = {stdout
, NULL
}, **s_ptr
= s_array
;
20 const char *const s1
= "hello world";
24 fputs ("bye", *s_ptr
);
27 fputs (s1
+10, *s_ptr
);
28 fputs (s1
+11, *s_ptr
);
30 /* Check side-effects when transforming fputs -> NOP. */
32 if (s_ptr
!= s_array
+1 || *s_ptr
!= 0)
35 /* Check side-effects when transforming fputs -> fputc. */
37 fputs ("\n", *s_ptr
++);
38 if (s_ptr
!= s_array
+1 || *s_ptr
!= 0)
41 /* Check side-effects when transforming fputs -> fwrite. */
43 fputs ("hello\n", *s_ptr
++);
44 if (s_ptr
!= s_array
+1 || *s_ptr
!= 0)
47 /* Test at least one instance of the __builtin_ style. We do this
48 to ensure that it works and that the prototype is correct. */
50 __builtin_fputs ("", *s_ptr
);
51 /* These builtin stubs are called by __builtin_fputs, ensure their
52 prototypes are set correctly too. */
53 __builtin_fputc ('\n', *s_ptr
);
54 __builtin_fwrite ("hello\n", 1, 6, *s_ptr
);
56 /* Check side-effects in conditional expression. */
58 fputs (i
++ ? "f" : "x", *s_ptr
++);
59 if (s_ptr
!= s_array
+1 || *s_ptr
!= 0 || i
!= 1)
61 fputs (--i
? "\n" : "\n", *--s_ptr
);
62 if (s_ptr
!= s_array
|| i
!= 0)
68 #if defined (__OPTIMIZE__) && ! defined (__OPTIMIZE_SIZE__)
69 /* When optimizing, all the above cases should be transformed into
70 something else. So any remaining calls to the original function
72 __attribute__ ((noinline
))
74 fputs(const char *string
, FILE *stream
)