diff options
author | Saleem Abdulrasool <compnerd@compnerd.org> | 2018-09-19 18:13:34 +0000 |
---|---|---|
committer | Saleem Abdulrasool <compnerd@compnerd.org> | 2018-09-19 18:13:34 +0000 |
commit | 29bf94d86fba0babf426e3d25abaae24dd9971bd (patch) | |
tree | d799b7ebbcc4e72f7f5f03f95cc0f051da646791 | |
parent | 8191d63c3bb4fb20afdc30a0681c072d18b6dcfc (diff) | |
download | bcm5719-llvm-29bf94d86fba0babf426e3d25abaae24dd9971bd.tar.gz bcm5719-llvm-29bf94d86fba0babf426e3d25abaae24dd9971bd.zip |
Sema: handle `wint_t` more carefully for printf checking
In the case that `win_t` is an `unsigned short` (e.g. on Windows), we would
previously incorrectly diagnose the conversion because we would immediately
promote the argument type from `wint_t` (aka `unsigned short`) to `int` before
checking if the type matched. This should repair the Windows hosted bots.
llvm-svn: 342565
-rw-r--r-- | clang/lib/Analysis/FormatString.cpp | 10 | ||||
-rw-r--r-- | clang/test/Sema/format-strings-ms.c | 3 | ||||
-rw-r--r-- | clang/test/Sema/format-strings.c | 4 |
3 files changed, 11 insertions, 6 deletions
diff --git a/clang/lib/Analysis/FormatString.cpp b/clang/lib/Analysis/FormatString.cpp index f37e4affae3..0bab50c569f 100644 --- a/clang/lib/Analysis/FormatString.cpp +++ b/clang/lib/Analysis/FormatString.cpp @@ -406,12 +406,14 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const { } case WIntTy: { + QualType WInt = C.getCanonicalType(C.getWIntType()).getUnqualifiedType(); - QualType PromoArg = - argTy->isPromotableIntegerType() - ? C.getPromotedIntegerType(argTy) : argTy; + if (C.getCanonicalType(argTy).getUnqualifiedType() == WInt) + return Match; - QualType WInt = C.getCanonicalType(C.getWIntType()).getUnqualifiedType(); + QualType PromoArg = argTy->isPromotableIntegerType() + ? C.getPromotedIntegerType(argTy) + : argTy; PromoArg = C.getCanonicalType(PromoArg).getUnqualifiedType(); // If the promoted argument is the corresponding signed type of the diff --git a/clang/test/Sema/format-strings-ms.c b/clang/test/Sema/format-strings-ms.c index 9887b461f61..56a349051d4 100644 --- a/clang/test/Sema/format-strings-ms.c +++ b/clang/test/Sema/format-strings-ms.c @@ -13,7 +13,6 @@ void non_iso_warning_test(__int32 i32, __int64 i64, wchar_t c, void *p) { printf("%I32d", i32); // expected-warning{{'I32' length modifier is not supported by ISO C}} printf("%I64d", i64); // expected-warning{{'I64' length modifier is not supported by ISO C}} printf("%wc", c); // expected-warning{{'w' length modifier is not supported by ISO C}} - // expected-warning@-1{{format specifies type 'wint_t' (aka 'unsigned short') but the argument has type 'wchar_t' (aka 'unsigned short')}} printf("%Z", p); // expected-warning{{'Z' conversion specifier is not supported by ISO C}} } @@ -36,7 +35,7 @@ void unsigned_test() { } void w_test(wchar_t c, wchar_t *s) { - printf("%wc", c); // expected-warning{{format specifies type 'wint_t' (aka 'unsigned short') but the argument has type 'wchar_t' (aka 'unsigned short')}} + printf("%wc", c); printf("%wC", c); printf("%C", c); printf("%ws", s); diff --git a/clang/test/Sema/format-strings.c b/clang/test/Sema/format-strings.c index 54651226adc..6630acdbc28 100644 --- a/clang/test/Sema/format-strings.c +++ b/clang/test/Sema/format-strings.c @@ -401,7 +401,11 @@ void bug7377_bad_length_mod_usage() { void pr7981(wint_t c, wchar_t c2) { printf("%lc", c); // no-warning printf("%lc", 1.0); // expected-warning{{the argument has type 'double'}} +#if __WINT_WIDTH__ == 4 printf("%lc", (char) 1); // no-warning +#else + printf("%lc", (char) 1); // expected-warning{{the argument has type 'char'}} +#endif printf("%lc", &c); // expected-warning{{the argument has type 'wint_t *'}} // If wint_t and wchar_t are the same width and wint_t is signed where // wchar_t is unsigned, an implicit conversion isn't possible. |