diff options
author | Hans Wennborg <hans@hanshq.net> | 2011-10-27 08:29:09 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2011-10-27 08:29:09 +0000 |
commit | 29e97cb35fab314388f62b68fefa78947e93c1dc (patch) | |
tree | ef30883ed59f503100b456acf04d5f319e176cea /test/Sema/format-strings-size_t.c | |
parent | 98a9203d80b6a5ff90edf037b1595f553fc81b15 (diff) |
Teach format string analysis that "%zu" means size_t.
The code had it backwards, thinking size_t was signed, and using that for "%zd".
Also let the analysis get the types for (u)intmax_t while we are at it.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143099 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Sema/format-strings-size_t.c')
-rw-r--r-- | test/Sema/format-strings-size_t.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/test/Sema/format-strings-size_t.c b/test/Sema/format-strings-size_t.c new file mode 100644 index 0000000000..c86a9e4428 --- /dev/null +++ b/test/Sema/format-strings-size_t.c @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s + +int printf(char const *, ...); + +void test(void) { + // size_t + printf("%zu", (double)42); // expected-warning {{conversion specifies type 'unsigned long' but the argument has type 'double''}} + + // intmax_t / uintmax_t + printf("%jd", (double)42); // expected-warning {{conversion specifies type 'long' but the argument has type 'double''}} + printf("%ju", (double)42); // expected-warning {{conversion specifies type 'unsigned long' but the argument has type 'double''}} + + // ptrdiff_t + printf("%td", (double)42); // expected-warning {{conversion specifies type 'long' but the argument has type 'double''}} +} |