diff options
-rw-r--r-- | lib/Analysis/FormatString.cpp | 4 | ||||
-rw-r--r-- | test/Sema/format-strings.c | 9 |
2 files changed, 11 insertions, 2 deletions
diff --git a/lib/Analysis/FormatString.cpp b/lib/Analysis/FormatString.cpp index c1b5ea8a65..9a8639015c 100644 --- a/lib/Analysis/FormatString.cpp +++ b/lib/Analysis/FormatString.cpp @@ -225,10 +225,10 @@ bool ArgTypeResult::matchesType(ASTContext &C, QualType argTy) const { break; case BuiltinType::Char_S: case BuiltinType::SChar: - return T == C.UnsignedCharTy; + return T == C.SignedCharTy; case BuiltinType::Char_U: case BuiltinType::UChar: - return T == C.SignedCharTy; + return T == C.UnsignedCharTy; case BuiltinType::Short: return T == C.UnsignedShortTy; case BuiltinType::UShort: diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c index 35210c341a..83f96ff3a0 100644 --- a/test/Sema/format-strings.c +++ b/test/Sema/format-strings.c @@ -363,3 +363,12 @@ int printf(const char * restrict, ...) __attribute__((__format__ (__printf__, 1, void rdar9612060(void) { printf("%s", 2); // expected-warning{{conversion specifies type 'char *' but the argument has type 'int'}} } + +void check_char(unsigned char x, signed char y) { + printf("%c", y); // no-warning + printf("%hhu", x); // no-warning + printf("%hhi", y); // no-warning + printf("%hhi", x); // expected-warning{{conversion specifies type 'signed char' but the argument has type 'unsigned char'}} + printf("%c", x); // no-warning + printf("%hhu", y); // expected-warning{{conversion specifies type 'unsigned char' but the argument has type 'signed char'}} +} |