2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / gcc.c-torture / execute / stdio-opt-2.c
blob833017ee5472091f722ce23ac73d5f77c452731d
1 /* Copyright (C) 2000 Free Software Foundation.
3 Ensure all expected transformations of builtin printf occur and
4 that we honor side effects in the arguments.
6 Written by Kaveh R. Ghazi, 12/4/2000. */
8 extern int printf (const char *, ...);
9 extern void abort(void);
11 int main()
13 const char *const s1 = "hello world";
14 const char *const s2[] = { s1, 0 }, *const*s3;
16 printf ("%s\n", "hello");
17 printf ("%s\n", *s2);
18 s3 = s2;
19 printf ("%s\n", *s3++);
20 if (s3 != s2+1 || *s3 != 0)
21 abort();
23 printf ("%c", '\n');
24 printf ("%c", **s2);
25 s3 = s2;
26 printf ("%c", **s3++);
27 if (s3 != s2+1 || *s3 != 0)
28 abort();
30 printf ("\n");
31 printf ("hello world\n");
33 /* Test at least one instance of the __builtin_ style. We do this
34 to ensure that it works and that the prototype is correct. */
35 __builtin_printf ("%s\n", "hello");
36 /* These builtin stubs are called by __builtin_printf, ensure their
37 prototypes are set correctly too. */
38 __builtin_putchar ('\n');
39 __builtin_puts ("hello");
41 return 0;
44 #ifdef __OPTIMIZE__
45 /* When optimizing, all the above cases should be transformed into
46 something else. So any remaining calls to the original function
47 should abort. */
48 __attribute__ ((noinline))
49 static int
50 printf (const char *string, ...)
52 abort();
54 #endif