OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [testsuite/] [gcc.c-torture/] [execute/] [printf-chk-1.c] - Blame information for rev 825

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 149 jeremybenn
#include <stdio.h>
2
#include <stdlib.h>
3
#include <stdarg.h>
4
 
5
volatile int should_optimize;
6
 
7
int
8
__attribute__((noinline))
9
__printf_chk (int flag, const char *fmt, ...)
10
{
11
  va_list ap;
12
  int ret;
13
#ifdef __OPTIMIZE__
14
  if (should_optimize)
15
    abort ();
16
#endif
17
  should_optimize = 1;
18
  va_start (ap, fmt);
19
  ret = vprintf (fmt, ap);
20
  va_end (ap);
21
  return ret;
22
}
23
 
24
int
25
main (void)
26
{
27
#define test(ret, opt, args...) \
28
  should_optimize = opt;                \
29
  __printf_chk (1, args);               \
30
  if (!should_optimize)                 \
31
    abort ();                           \
32
  should_optimize = 0;                   \
33
  if (__printf_chk (1, args) != ret)    \
34
    abort ();                           \
35
  if (!should_optimize)                 \
36
    abort ();
37
  test (5, 0, "hello");
38
  test (6, 1, "hello\n");
39
  test (1, 1, "a");
40
  test (0, 1, "");
41
  test (5, 0, "%s", "hello");
42
  test (6, 1, "%s", "hello\n");
43
  test (1, 1, "%s", "a");
44
  test (0, 1, "%s", "");
45
  test (1, 1, "%c", 'x');
46
  test (7, 1, "%s\n", "hello\n");
47
  test (2, 0, "%d\n", 0);
48
  return 0;
49
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.