diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp --- a/clang/lib/AST/FormatString.cpp +++ b/clang/lib/AST/FormatString.cpp @@ -465,6 +465,24 @@ T == C.WideCharTy) return MatchPromotion; break; + case BuiltinType::Char_U: + if (T == C.UnsignedIntTy) + return MatchPromotion; + if (T == C.UnsignedShortTy) + return NoMatchPromotionTypeConfusion; + break; + case BuiltinType::Char_S: + if (T == C.IntTy) + return MatchPromotion; + if (T == C.ShortTy) + return NoMatchPromotionTypeConfusion; + break; + case BuiltinType::Half: + case BuiltinType::Float16: + case BuiltinType::Float: + if (T == C.DoubleTy) + return MatchPromotion; + break; case BuiltinType::Short: case BuiltinType::UShort: if (T == C.SignedCharTy || T == C.UnsignedCharTy) diff --git a/clang/test/Sema/attr-format.c b/clang/test/Sema/attr-format.c --- a/clang/test/Sema/attr-format.c +++ b/clang/test/Sema/attr-format.c @@ -94,13 +94,9 @@ d3("%s", 123); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}} } -__attribute__((format(printf, 1, 2))) void forward_fixed(const char *fmt, int i) { // expected-warning{{GCC requires a function with the 'format' attribute to be variadic}} - forward_fixed(fmt, i); - a(fmt, i); -} - -__attribute__((format(printf, 1, 2))) void forward_fixed_2(const char *fmt, int i, int j) { // expected-warning{{GCC requires a function with the 'format' attribute to be variadic}} - forward_fixed_2(fmt, i, j); - a(fmt, i); +__attribute__((format(printf, 1, 2))) +void forward_fixed(const char *fmt, char i, short j, int k, float l, double m) { // expected-warning{{GCC requires a function with the 'format' attribute to be variadic}} + forward_fixed(fmt, i, j, k, l, m); + a(fmt, i, j, k, l, m); } diff --git a/clang/test/SemaCXX/attr-format.cpp b/clang/test/SemaCXX/attr-format.cpp --- a/clang/test/SemaCXX/attr-format.cpp +++ b/clang/test/SemaCXX/attr-format.cpp @@ -78,6 +78,9 @@ format("%s %s %u %d %i %p\n", "hello", s, 10u, x, y, do_format); format("bad format %s"); // expected-warning{{more '%' conversions than data arguments}} + format("%c %c %hhd %hd %d\n", (char)'a', 'a', 'a', (short)123, (int)123); + format("%f %f %f\n", (__fp16)123.f, 123.f, 123.); + struct foo f; format_invalid_nonpod("hello %i", f); // expected-warning{{format specifies type 'int' but the argument has type 'struct foo'}}