Debian Codegraph @

gcc/testsuite/gcc.c-torture/execute/vprintf-chk-1.c

raw
1 /* { dg-skip-if "requires io" { freestanding } } */
2 /* { dg-xfail-run-if {unexpected PTX 'vprintf' return value} { nvptx-*-* } } */
3
4 #ifndef test
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <stdarg.h>
8
9 volatile int should_optimize;
10
11 int
12 __attribute__((noinline))
13 __vprintf_chk (int flag, const char *fmt, va_list ap)
14 {
15 #ifdef __OPTIMIZE__
16 if (should_optimize)
17 abort ();
18 #endif
19 should_optimize = 1;
20 return vprintf (fmt, ap);
21 }
22
23 void
24 inner (int x, ...)
25 {
26 va_list ap, ap2;
27 va_start (ap, x);
28 va_start (ap2, x);
29
30 switch (x)
31 {
32 #define test(n, ret, opt, fmt, args) \
33 case n: \
34 should_optimize = opt; \
35 __vprintf_chk (1, fmt, ap); \
36 if (! should_optimize) \
37 abort (); \
38 should_optimize = 0; \
39 if (__vprintf_chk (1, fmt, ap2) != ret) \
40 abort (); \
41 if (! should_optimize) \
42 abort (); \
43 break;
44 #include "vprintf-chk-1.c"
45 #undef test
46 default:
47 abort ();
48 }
49
50 va_end (ap);
51 va_end (ap2);
52 }
53
54 int
55 main (void)
56 {
57 #define test(n, ret, opt, fmt, args) \
58 inner args;
59 #include "vprintf-chk-1.c"
60 #undef test
61 return 0;
62 }
63
64 #else
65 test (0, 5, 0, "hello", (0));
66 test (1, 6, 1, "hello\n", (1));
67 test (2, 1, 1, "a", (2));
68 test (3, 0, 1, "", (3));
69 test (4, 5, 0, "%s", (4, "hello"));
70 test (5, 6, 0, "%s", (5, "hello\n"));
71 test (6, 1, 0, "%s", (6, "a"));
72 test (7, 0, 0, "%s", (7, ""));
73 test (8, 1, 0, "%c", (8, 'x'));
74 test (9, 7, 0, "%s\n", (9, "hello\n"));
75 test (10, 2, 0, "%d\n", (10, 0));
76 #endif