Home | History | Annotate | Download | only in Sema
      1 // RUN: %clang_cc1 -fsyntax-only -verify -triple i386-unknown-freebsd %s
      2 // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-unknown-freebsd %s
      3 
      4 // Test FreeBSD kernel printf extensions.
      5 int freebsd_kernel_printf(const char *, ...) __attribute__((__format__(__freebsd_kprintf__, 1, 2)));
      6 
      7 void check_freebsd_kernel_extensions(int i, long l, char *s)
      8 {
      9   // %b expects an int and a char *
     10   freebsd_kernel_printf("reg=%b\n", i, "\10\2BITTWO\1BITONE\n"); // no-warning
     11   freebsd_kernel_printf("reg=%b\n", l, "\10\2BITTWO\1BITONE\n"); // expected-warning{{format specifies type 'int' but the argument has type 'long'}}
     12   freebsd_kernel_printf("reg=%b\n", i, l); // expected-warning{{format specifies type 'char *' but the argument has type 'long'}}
     13   freebsd_kernel_printf("reg=%b\n", i); // expected-warning{{more '%' conversions than data arguments}}
     14   freebsd_kernel_printf("reg=%b\n", i, "\10\2BITTWO\1BITONE\n", l); // expected-warning{{data argument not used by format string}}
     15 
     16   // %D expects an unsigned char * and a char *
     17   freebsd_kernel_printf("%6D", s, ":"); // no-warning
     18   freebsd_kernel_printf("%6D", i, ":"); // expected-warning{{format specifies type 'void *' but the argument has type 'int'}}
     19   freebsd_kernel_printf("%6D", s, i); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}}
     20   freebsd_kernel_printf("%6D", s); // expected-warning{{more '%' conversions than data arguments}}
     21   freebsd_kernel_printf("%6D", s, ":", i); // expected-warning{{data argument not used by format string}}
     22 
     23   freebsd_kernel_printf("%*D", 42, s, ":"); // no-warning
     24   freebsd_kernel_printf("%*D", 42, i, ":"); // expected-warning{{format specifies type 'void *' but the argument has type 'int'}}
     25   freebsd_kernel_printf("%*D", 42, s, i); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}}
     26   freebsd_kernel_printf("%*D", 42, s); // expected-warning{{more '%' conversions than data arguments}}
     27   freebsd_kernel_printf("%*D", 42, s, ":", i); // expected-warning{{data argument not used by format string}}
     28 
     29   // %r expects an int
     30   freebsd_kernel_printf("%r", i); // no-warning
     31   freebsd_kernel_printf("%r", l); // expected-warning{{format specifies type 'int' but the argument has type 'long'}}
     32   freebsd_kernel_printf("%lr", i); // expected-warning{{format specifies type 'long' but the argument has type 'int'}}
     33   freebsd_kernel_printf("%lr", l); // no-warning
     34 
     35   // %y expects an int
     36   freebsd_kernel_printf("%y", i); // no-warning
     37   freebsd_kernel_printf("%y", l); // expected-warning{{format specifies type 'int' but the argument has type 'long'}}
     38   freebsd_kernel_printf("%ly", i); // expected-warning{{format specifies type 'long' but the argument has type 'int'}}
     39   freebsd_kernel_printf("%ly", l); // no-warning
     40 }
     41