diff options
author | Erik Pilkington <erik.pilkington@gmail.com> | 2019-10-04 19:20:27 +0000 |
---|---|---|
committer | Erik Pilkington <erik.pilkington@gmail.com> | 2019-10-04 19:20:27 +0000 |
commit | f758ad08d7d745e5cfd2bfe5c042d30fd7c39330 (patch) | |
tree | 337fb5b014792a3fa5a463daee85e7e4f6b5bb31 /test/Sema | |
parent | a22db94ad12e8ee1d7d6733329229d6b8047cba5 (diff) | |
download | clang-f758ad08d7d745e5cfd2bfe5c042d30fd7c39330.tar.gz |
[Sema] Split out -Wformat-type-confusion from -Wformat-pedantic
The warnings now in -Wformat-type-confusion don't align with how we interpret
'pedantic' in clang, and don't belong in -pedantic.
Differential revision: https://reviews.llvm.org/D67775
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@373774 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Sema')
-rw-r--r-- | test/Sema/format-bool.c | 8 | ||||
-rw-r--r-- | test/Sema/format-strings-pedantic.c | 20 | ||||
-rw-r--r-- | test/Sema/format-type-confusion.c | 26 |
3 files changed, 45 insertions, 9 deletions
diff --git a/test/Sema/format-bool.c b/test/Sema/format-bool.c index 53c2c7fd12..a592665494 100644 --- a/test/Sema/format-bool.c +++ b/test/Sema/format-bool.c @@ -1,8 +1,8 @@ // RUN: %clang_cc1 -xc %s -verify -DBOOL=_Bool // RUN: %clang_cc1 -xc++ %s -verify -DBOOL=bool // RUN: %clang_cc1 -xobjective-c %s -verify -DBOOL=_Bool -// RUN: %clang_cc1 -xc %s -verify -DBOOL=_Bool -Wformat-pedantic -DPEDANTIC -// RUN: %clang_cc1 -xc++ %s -verify -DBOOL=bool -Wformat-pedantic -DPEDANTIC +// RUN: %clang_cc1 -xc %s -verify -DBOOL=_Bool -Wformat-type-confusion -DTYPE_CONF +// RUN: %clang_cc1 -xc++ %s -verify -DBOOL=bool -Wformat-type-confusion -DTYPE_CONF __attribute__((format(__printf__, 1, 2))) int p(const char *fmt, ...); @@ -22,13 +22,13 @@ BOOL b; int main() { p("%d", b); p("%hd", b); -#ifdef PEDANTIC +#ifdef TYPE_CONF // expected-warning@-2 {{format specifies type 'short' but the argument has type}} #endif p("%hhd", b); p("%u", b); p("%hu", b); -#ifdef PEDANTIC +#ifdef TYPE_CONF // expected-warning@-2 {{format specifies type 'unsigned short' but the argument has type}} #endif p("%hhu", b); diff --git a/test/Sema/format-strings-pedantic.c b/test/Sema/format-strings-pedantic.c index 8fb298ab79..6c206bac04 100644 --- a/test/Sema/format-strings-pedantic.c +++ b/test/Sema/format-strings-pedantic.c @@ -1,10 +1,20 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -Wformat -Wformat-pedantic -isystem %S/Inputs %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-format -Wformat-pedantic %s +// RUN: %clang_cc1 -xobjective-c -fblocks -fsyntax-only -verify -Wno-format -Wformat-pedantic %s +// RUN: %clang_cc1 -xc++ -fsyntax-only -verify -Wno-format -Wformat-pedantic %s +__attribute__((format(printf, 1, 2))) int printf(const char *restrict, ...); -typedef unsigned char uint8_t; +int main() { + printf("%p", (int *)0); // expected-warning {{format specifies type 'void *' but the argument has type 'int *'}} + printf("%p", (void *)0); -void print_char_as_short() { - printf("%hu\n", (unsigned char)1); // expected-warning{{format specifies type 'unsigned short' but the argument has type 'unsigned char'}} - printf("%hu\n", (uint8_t)1); // expected-warning{{format specifies type 'unsigned short' but the argument has type 'uint8_t' (aka 'unsigned char')}} +#ifdef __OBJC__ + printf("%p", ^{}); // expected-warning {{format specifies type 'void *' but the argument has type 'void (^)(void)'}} + printf("%p", (id)0); // expected-warning {{format specifies type 'void *' but the argument has type 'id'}} +#endif + +#ifdef __cplusplus + printf("%p", nullptr); // expected-warning {{format specifies type 'void *' but the argument has type 'nullptr_t'}} +#endif } diff --git a/test/Sema/format-type-confusion.c b/test/Sema/format-type-confusion.c new file mode 100644 index 0000000000..f02bd56676 --- /dev/null +++ b/test/Sema/format-type-confusion.c @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin9.0 -fsyntax-only -verify -Wno-format -Wformat-type-confusion %s + +__attribute__((format(__printf__, 1, 2))) +int printf(const char *msg, ...); + +#define FMT "%hd %hu %d %u %hhd %hhu %c" + +int main() { + _Bool b = 0; + printf(FMT, + b, // expected-warning {{format specifies type 'short' but the argument has type '_Bool'}} + b, // expected-warning {{format specifies type 'unsigned short' but the argument has type '_Bool'}} + b, b, b, b, b); + + unsigned char uc = 0; + printf(FMT, + uc, // expected-warning {{format specifies type 'short' but the argument has type 'unsigned char'}} + uc, // expected-warning {{format specifies type 'unsigned short' but the argument has type 'unsigned char'}} + uc, uc, uc, uc, uc); + + signed char sc = 0; + printf(FMT, + sc, // expected-warning {{format specifies type 'short' but the argument has type 'signed char'}} + sc, // expected-warning {{format specifies type 'unsigned short' but the argument has type 'signed char'}} + sc, sc, sc, sc, sc); +} |