summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/tree-ssa/pr69196-1.c
blob: 5f92447854bf8ea899e1d92f242135fb53c7b6c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* { dg-do compile { target sparc*-*-* x86_64-*-* } } */
/* { dg-options "-O2 -fdump-tree-thread1-details -fdisable-tree-ethread" } */

/* { dg-final { scan-tree-dump "FSM did not thread around loop and would copy too many statements" "thread1" } } */


typedef __builtin_va_list __gnuc_va_list;
typedef __gnuc_va_list va_list;
extern void rtems_putc(char c);

void vprintk(
  const char *fmt,
  va_list ap
)
{
  for (; *fmt != '\0'; fmt++) {
    unsigned base = 0;
    unsigned width = 0;
    enum {
      LFLAG_INT,
      LFLAG_LONG,
      LFLAG_LONG_LONG
    } lflag = LFLAG_INT;
    _Bool minus = 0;
    _Bool sign = 0;
    char lead = ' ';
    char c = *fmt;
    long long num;

    if (c != '%') {
      rtems_putc(c);
      continue;
    }

    ++fmt; c = *fmt;

    if (c == '0') {
      lead = '0';
      ++fmt; c = *fmt;
    }

    if (c == '-') {
      minus = 1;
      ++fmt; c = *fmt;
    }

    while (c >= '0' && c <= '9' ) {
      width *= 10;
      width += ((unsigned) c - '0');
      ++fmt; c = *fmt;
    }

    if (c == 'l') {
      lflag = LFLAG_LONG;
      ++fmt; c = *fmt;

      if (c == 'l') {
        lflag = LFLAG_LONG_LONG;
        ++fmt; c = *fmt;
      }
    }

    if ( c == 'c' ) {

      char chr = (char) __builtin_va_arg(ap,int);
      rtems_putc(chr);
      continue;
    }

    if ( c == 's' ) {
      unsigned i, len;
      char *s, *str;

      str = __builtin_va_arg(ap,char *);

      if ( str == ((void *)0) ) {
        str = "";
      }


      for ( len=0, s=str ; *s ; len++, s++ )
        ;


      if ( !minus )
        for ( i=len ; i<width ; i++ )
          rtems_putc(' ');


      if (width == 0) {
          width = len;
      }


      for ( i=0 ; i<width && *str ; str++ )
        rtems_putc(*str);


      if ( minus )
        for ( i=len ; i<width ; i++ )
          rtems_putc(' ');

      continue;
    }


    if ( c == 'o' || c == 'O' ) {
      base = 8; sign = 0;
    } else if ( c == 'i' || c == 'I' ||
                c == 'd' || c == 'D' ) {
      base = 10; sign = 1;
    } else if ( c == 'u' || c == 'U' ) {
      base = 10; sign = 0;
    } else if ( c == 'x' || c == 'X' ) {
      base = 16; sign = 0;
    } else if ( c == 'p' ) {
      base = 16; sign = 0; lflag = LFLAG_LONG;
    } else {
      rtems_putc(c);
      continue;
    }

    switch (lflag) {
      case LFLAG_LONG:
        num = sign ? (long long) __builtin_va_arg(ap,long)
          : (long long) __builtin_va_arg(ap,unsigned long);
        break;
      case LFLAG_LONG_LONG:
        num = __builtin_va_arg(ap,long long);
        break;
      case LFLAG_INT:
      default:
        num = sign ? (long long) __builtin_va_arg(ap,int)
          : (long long) __builtin_va_arg(ap,unsigned int);
        break;
    }
  }
}