| 1 |
/* { dg-require-effective-target indirect_jumps } */ |
| 2 |
|
| 3 |
typedef long unsigned int size_t; |
| 4 |
extern void abort (void); |
| 5 |
extern char *strcpy (char *, const char *); |
| 6 |
extern int strcmp (const char *, const char *); |
| 7 |
typedef __builtin_va_list va_list; |
| 8 |
static const char null[] = "(null)"; |
| 9 |
int g (char *s, const char *format, va_list ap) |
| 10 |
{ |
| 11 |
const char *f; |
| 12 |
const char *string; |
| 13 |
char spec; |
| 14 |
static const void *step0_jumps[] = { |
| 15 |
&&do_precision, |
| 16 |
&&do_form_integer, |
| 17 |
&&do_form_string, |
| 18 |
}; |
| 19 |
f = format; |
| 20 |
if (*f == '\0') |
| 21 |
goto all_done; |
| 22 |
do |
| 23 |
{ |
| 24 |
spec = (*++f); |
| 25 |
goto *(step0_jumps[2]); |
| 26 |
|
| 27 |
/* begin switch table. */ |
| 28 |
do_precision: |
| 29 |
++f; |
| 30 |
__builtin_va_arg (ap, int); |
| 31 |
spec = *f; |
| 32 |
goto *(step0_jumps[2]); |
| 33 |
|
| 34 |
do_form_integer: |
| 35 |
__builtin_va_arg (ap, unsigned long int); |
| 36 |
goto end; |
| 37 |
|
| 38 |
do_form_string: |
| 39 |
string = __builtin_va_arg (ap, const char *); |
| 40 |
strcpy (s, string); |
| 41 |
|
| 42 |
/* End of switch table. */ |
| 43 |
end: |
| 44 |
++f; |
| 45 |
} |
| 46 |
while (*f != '\0'); |
| 47 |
|
| 48 |
all_done: |
| 49 |
return 0; |
| 50 |
} |
| 51 |
|
| 52 |
void |
| 53 |
f (char *s, const char *f, ...) |
| 54 |
{ |
| 55 |
va_list ap; |
| 56 |
__builtin_va_start (ap, f); |
| 57 |
g (s, f, ap); |
| 58 |
__builtin_va_end (ap); |
| 59 |
} |
| 60 |
|
| 61 |
int |
| 62 |
main (void) |
| 63 |
{ |
| 64 |
char buf[10]; |
| 65 |
f (buf, "%s", "asdf", 0); |
| 66 |
if (strcmp (buf, "asdf")) |
| 67 |
abort (); |
| 68 |
return 0; |
| 69 |
} |
| 70 |
|