]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/gcc.c-torture/execute/printf-chk-1.c
Get rid of dg-skip-if etc. default args
[thirdparty/gcc.git] / gcc / testsuite / gcc.c-torture / execute / printf-chk-1.c
CommitLineData
4f4b0ab8 1/* { dg-skip-if "requires io" { freestanding } } */
a560e5d4 2
10a0d495
JJ
3#include <stdio.h>
4#include <stdlib.h>
5#include <stdarg.h>
6
7volatile int should_optimize;
8
9int
10__attribute__((noinline))
11__printf_chk (int flag, const char *fmt, ...)
12{
13 va_list ap;
14 int ret;
15#ifdef __OPTIMIZE__
16 if (should_optimize)
17 abort ();
18#endif
19 should_optimize = 1;
20 va_start (ap, fmt);
21 ret = vprintf (fmt, ap);
22 va_end (ap);
23 return ret;
24}
25
26int
27main (void)
28{
29#define test(ret, opt, args...) \
30 should_optimize = opt; \
31 __printf_chk (1, args); \
32 if (!should_optimize) \
33 abort (); \
34 should_optimize = 0; \
35 if (__printf_chk (1, args) != ret) \
36 abort (); \
37 if (!should_optimize) \
38 abort ();
39 test (5, 0, "hello");
40 test (6, 1, "hello\n");
41 test (1, 1, "a");
42 test (0, 1, "");
43 test (5, 0, "%s", "hello");
44 test (6, 1, "%s", "hello\n");
45 test (1, 1, "%s", "a");
46 test (0, 1, "%s", "");
47 test (1, 1, "%c", 'x');
48 test (7, 1, "%s\n", "hello\n");
49 test (2, 0, "%d\n", 0);
50 return 0;
51}