diff options
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/Sema/attr-format.c | 7 | ||||
-rw-r--r-- | clang/test/Sema/format-strings-freebsd.c | 40 |
2 files changed, 47 insertions, 0 deletions
diff --git a/clang/test/Sema/attr-format.c b/clang/test/Sema/attr-format.c index 21d9585a57e..3ea9d79a5fd 100644 --- a/clang/test/Sema/attr-format.c +++ b/clang/test/Sema/attr-format.c @@ -57,6 +57,13 @@ void callnull(void){ null(0, (int*)0); // expected-warning {{incompatible pointer types}} } +// FreeBSD kernel extensions +void a3(const char *a, ...) __attribute__((format(freebsd_kprintf, 1,2))); // no-error +void b3(const char *a, ...) __attribute__((format(freebsd_kprintf, 1,1))); // expected-error {{'format' attribute parameter 3 is out of bounds}} +void c3(const char *a, ...) __attribute__((format(freebsd_kprintf, 0,2))); // expected-error {{'format' attribute parameter 2 is out of bounds}} +void d3(const char *a, int c) __attribute__((format(freebsd_kprintf, 1,2))); // expected-error {{format attribute requires variadic function}} +void e3(char *str, int c, ...) __attribute__((format(freebsd_kprintf, 2,3))); // expected-error {{format argument not a string type}} + // PR4470 diff --git a/clang/test/Sema/format-strings-freebsd.c b/clang/test/Sema/format-strings-freebsd.c new file mode 100644 index 00000000000..cdf273ae109 --- /dev/null +++ b/clang/test/Sema/format-strings-freebsd.c @@ -0,0 +1,40 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -triple i386-unknown-freebsd %s +// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-unknown-freebsd %s + +// Test FreeBSD kernel printf extensions. +int freebsd_kernel_printf(const char *, ...) __attribute__((__format__(__freebsd_kprintf__, 1, 2))); + +void check_freebsd_kernel_extensions(int i, long l, char *s) +{ + // %b expects an int and a char * + freebsd_kernel_printf("reg=%b\n", i, "\10\2BITTWO\1BITONE\n"); // no-warning + freebsd_kernel_printf("reg=%b\n", l, "\10\2BITTWO\1BITONE\n"); // expected-warning{{format specifies type 'int' but the argument has type 'long'}} + freebsd_kernel_printf("reg=%b\n", i, l); // expected-warning{{format specifies type 'char *' but the argument has type 'long'}} + freebsd_kernel_printf("reg=%b\n", i); // expected-warning{{more '%' conversions than data arguments}} + freebsd_kernel_printf("reg=%b\n", i, "\10\2BITTWO\1BITONE\n", l); // expected-warning{{data argument not used by format string}} + + // %D expects an unsigned char * and a char * + freebsd_kernel_printf("%6D", s, ":"); // no-warning + freebsd_kernel_printf("%6D", i, ":"); // expected-warning{{format specifies type 'void *' but the argument has type 'int'}} + freebsd_kernel_printf("%6D", s, i); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}} + freebsd_kernel_printf("%6D", s); // expected-warning{{more '%' conversions than data arguments}} + freebsd_kernel_printf("%6D", s, ":", i); // expected-warning{{data argument not used by format string}} + + freebsd_kernel_printf("%*D", 42, s, ":"); // no-warning + freebsd_kernel_printf("%*D", 42, i, ":"); // expected-warning{{format specifies type 'void *' but the argument has type 'int'}} + freebsd_kernel_printf("%*D", 42, s, i); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}} + freebsd_kernel_printf("%*D", 42, s); // expected-warning{{more '%' conversions than data arguments}} + freebsd_kernel_printf("%*D", 42, s, ":", i); // expected-warning{{data argument not used by format string}} + + // %r expects an int + freebsd_kernel_printf("%r", i); // no-warning + freebsd_kernel_printf("%r", l); // expected-warning{{format specifies type 'int' but the argument has type 'long'}} + freebsd_kernel_printf("%lr", i); // expected-warning{{format specifies type 'long' but the argument has type 'int'}} + freebsd_kernel_printf("%lr", l); // no-warning + + // %y expects an int + freebsd_kernel_printf("%y", i); // no-warning + freebsd_kernel_printf("%y", l); // expected-warning{{format specifies type 'int' but the argument has type 'long'}} + freebsd_kernel_printf("%ly", i); // expected-warning{{format specifies type 'long' but the argument has type 'int'}} + freebsd_kernel_printf("%ly", l); // no-warning +} |