1 /* { dg-do compile { target sparc*-*-* i?86-*-* x86_64-*-* } } */
2 /* { dg-options "-O2 -fdump-tree-thread1-details -fdisable-tree-ethread" } */
3
4 /* { dg-final { scan-tree-dump "FSM did not thread around loop and would copy too many statements" "thread1" } } */
5
6
7 typedef __builtin_va_list __gnuc_va_list;
8 typedef __gnuc_va_list va_list;
9 extern void rtems_putc(char c);
10
vprintk(const char * fmt,va_list ap)11 void vprintk(
12 const char *fmt,
13 va_list ap
14 )
15 {
16 for (; *fmt != '\0'; fmt++) {
17 unsigned base = 0;
18 unsigned width = 0;
19 enum {
20 LFLAG_INT,
21 LFLAG_LONG,
22 LFLAG_LONG_LONG
23 } lflag = LFLAG_INT;
24 _Bool minus = 0;
25 _Bool sign = 0;
26 char lead = ' ';
27 char c = *fmt;
28 long long num;
29
30 if (c != '%') {
31 rtems_putc(c);
32 continue;
33 }
34
35 ++fmt; c = *fmt;
36
37 if (c == '0') {
38 lead = '0';
39 ++fmt; c = *fmt;
40 }
41
42 if (c == '-') {
43 minus = 1;
44 ++fmt; c = *fmt;
45 }
46
47 while (c >= '0' && c <= '9' ) {
48 width *= 10;
49 width += ((unsigned) c - '0');
50 ++fmt; c = *fmt;
51 }
52
53 if (c == 'l') {
54 lflag = LFLAG_LONG;
55 ++fmt; c = *fmt;
56
57 if (c == 'l') {
58 lflag = LFLAG_LONG_LONG;
59 ++fmt; c = *fmt;
60 }
61 }
62
63 if ( c == 'c' ) {
64
65 char chr = (char) __builtin_va_arg(ap,int);
66 rtems_putc(chr);
67 continue;
68 }
69
70 if ( c == 's' ) {
71 unsigned i, len;
72 char *s, *str;
73
74 str = __builtin_va_arg(ap,char *);
75
76 if ( str == ((void *)0) ) {
77 str = "";
78 }
79
80
81 for ( len=0, s=str ; *s ; len++, s++ )
82 ;
83
84
85 if ( !minus )
86 for ( i=len ; i<width ; i++ )
87 rtems_putc(' ');
88
89
90 if (width == 0) {
91 width = len;
92 }
93
94
95 for ( i=0 ; i<width && *str ; str++ )
96 rtems_putc(*str);
97
98
99 if ( minus )
100 for ( i=len ; i<width ; i++ )
101 rtems_putc(' ');
102
103 continue;
104 }
105
106
107 if ( c == 'o' || c == 'O' ) {
108 base = 8; sign = 0;
109 } else if ( c == 'i' || c == 'I' ||
110 c == 'd' || c == 'D' ) {
111 base = 10; sign = 1;
112 } else if ( c == 'u' || c == 'U' ) {
113 base = 10; sign = 0;
114 } else if ( c == 'x' || c == 'X' ) {
115 base = 16; sign = 0;
116 } else if ( c == 'p' ) {
117 base = 16; sign = 0; lflag = LFLAG_LONG;
118 } else {
119 rtems_putc(c);
120 continue;
121 }
122
123 switch (lflag) {
124 case LFLAG_LONG:
125 num = sign ? (long long) __builtin_va_arg(ap,long)
126 : (long long) __builtin_va_arg(ap,unsigned long);
127 break;
128 case LFLAG_LONG_LONG:
129 num = __builtin_va_arg(ap,long long);
130 break;
131 case LFLAG_INT:
132 default:
133 num = sign ? (long long) __builtin_va_arg(ap,int)
134 : (long long) __builtin_va_arg(ap,unsigned int);
135 break;
136 }
137 }
138 }
139