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
|
/* { dg-additional-options "-fno-analyzer-call-summaries -fno-analyzer-state-merge -Wno-analyzer-too-complex" } */
void test_format_string (const char *fmt, ...)
{
__builtin_va_list ap;
__builtin_va_start (ap, fmt);
while (*fmt)
switch (*fmt++)
{
case 's':
{
const char *s = __builtin_va_arg (ap, char *); /* { dg-warning "'va_arg' expected 'const char \\*' but received 'int' for variadic argument 1 of 'ap'" } */
__builtin_printf ("string: %s\n", s);
}
break;
case 'd':
{
int i = __builtin_va_arg (ap, int); /* { dg-warning "'va_arg' expected 'int' but received '\[^\n\r\]*' for variadic argument 1 of 'ap'" "type mismatch from wrong_type_for_percent_d" } */
/* { dg-warning "'ap' has no more arguments \\(1 consumed\\)" "not_enough_args" { target *-*-* } .-1 } */
__builtin_printf ("int: %d\n", i);
}
break;
case 'c':
{
char c = (char)__builtin_va_arg (ap, int);
__builtin_printf ("char: %c\n", c);
}
break;
}
__builtin_va_end (ap);
}
void test_missing_va_start (const char *fmt, ...)
{
__builtin_va_list ap;
while (*fmt)
switch (*fmt++)
{
case 's':
{
const char *s = __builtin_va_arg (ap, char *); /* { dg-warning "use of uninitialized value 'ap'" } */
__builtin_printf ("string: %s\n", s);
}
break;
case 'd':
{
int i = __builtin_va_arg (ap, int); /* { dg-warning "use of uninitialized value 'ap'" } */
__builtin_printf ("int: %d\n", i);
}
break;
case 'c':
{
char c = (char)__builtin_va_arg (ap, int); /* { dg-warning "use of uninitialized value 'ap'" } */
__builtin_printf ("char: %c\n", c);
}
break;
}
__builtin_va_end (ap);
}
void test_missing_va_end (const char *fmt, ...)
{
__builtin_va_list ap;
__builtin_va_start (ap, fmt);
while (*fmt)
switch (*fmt++)
{
case 's':
{
const char *s = __builtin_va_arg (ap, char *);
__builtin_printf ("string: %s\n", s);
}
break;
case 'd':
{
int i = __builtin_va_arg (ap, int);
__builtin_printf ("int: %d\n", i);
}
break;
case 'c':
{
char c = (char)__builtin_va_arg (ap, int);
__builtin_printf ("char: %c\n", c);
}
break;
}
} /* { dg-warning "missing call to 'va_end'" } */
void wrong_type_for_percent_s (void)
{
test_format_string ("%s", 42);
}
void wrong_type_for_percent_d (void)
{
test_format_string ("%d", "foo");
}
void not_enough_args (void)
{
test_format_string ("%s%d", "foo");
}
|