From 39fcc9a984e2820e4ea0fa2ac4abd17d9f3a31df Mon Sep 17 00:00:00 2001 From: dim Date: Sun, 20 Feb 2011 13:06:31 +0000 Subject: Vendor import of clang trunk r126079: http://llvm.org/svn/llvm-project/cfe/trunk@126079 --- test/Sema/format-strings.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'test/Sema/format-strings.c') diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c index 2325454..be506d7 100644 --- a/test/Sema/format-strings.c +++ b/test/Sema/format-strings.c @@ -174,7 +174,16 @@ void test10(int x, float f, int i, long long lli) { printf("%.0Lf", (long double) 1.0); // no-warning printf("%c\n", "x"); // expected-warning{{conversion specifies type 'int' but the argument has type 'char *'}} printf("%c\n", 1.23); // expected-warning{{conversion specifies type 'int' but the argument has type 'double'}} -} + printf("Format %d, is %! %f", 1, 2, 4.4); // expected-warning{{invalid conversion specifier '!'}} +} + +typedef unsigned char uint8_t; + +void should_understand_small_integers() { + printf("%hhu", (short) 10); // expected-warning{{conversion specifies type 'unsigned char' but the argument has type 'short'}} + printf("%hu\n", (unsigned char) 1); // expected-warning{{conversion specifies type 'unsigned short' but the argument has type 'unsigned char'}} + printf("%hu\n", (uint8_t)1); // expected-warning{{conversion specifies type 'unsigned short' but the argument has type 'uint8_t'}} +} void test11(void *p, char *s) { printf("%p", p); // no-warning @@ -301,3 +310,33 @@ void pr7981(wint_t c, wchar_t c2) { printf("%lc", c2); // no-warning } +// -Wformat-security says NULL is not a string literal +void rdar8269537() { + // This is likely to crash in most cases, but -Wformat-nonliteral technically + // doesn't warn in this case. + printf(0); // no-warning +} + +// Handle functions with multiple format attributes. +extern void rdar8332221_vprintf_scanf(const char *, va_list, const char *, ...) + __attribute__((__format__(__printf__, 1, 0))) + __attribute__((__format__(__scanf__, 3, 4))); + +void rdar8332221(va_list ap, int *x, long *y) { + rdar8332221_vprintf_scanf("%", ap, "%d", x); // expected-warning{{incomplete format specifier}} +} + +// PR8641 +void pr8641() { + printf("%#x\n", 10); + printf("%#X\n", 10); +} + +void posix_extensions() { + // Test %'d, "thousands grouping". + // + printf("%'d\n", 123456789); // no-warning + printf("%'i\n", 123456789); // no-warning + printf("%'f\n", (float) 1.0); // no-warning + printf("%'p\n", (void*) 0); // expected-warning{{results in undefined behavior with 'p' conversion specifier}} +} -- cgit v1.1