Make -Wformat accept printf("%hhx", c); with -funsigned-char

For "%hhx", printf expects an unsigned char. This makes Clang
accept a 'char' argument for that also when using -funsigned-char.

This fixes PR12761.

llvm-svn: 156388
This commit is contained in:
Hans Wennborg 2012-05-08 17:21:31 +00:00
parent 24ac479a7d
commit 967b9cec23
2 changed files with 7 additions and 2 deletions

View File

@ -265,10 +265,9 @@ bool ArgTypeResult::matchesType(ASTContext &C, QualType argTy) const {
break;
case BuiltinType::Char_S:
case BuiltinType::SChar:
return T == C.UnsignedCharTy;
case BuiltinType::Char_U:
case BuiltinType::UChar:
return T == C.SignedCharTy;
return T == C.UnsignedCharTy || T == C.SignedCharTy;
case BuiltinType::Short:
return T == C.UnsignedShortTy;
case BuiltinType::UShort:

View File

@ -1,4 +1,5 @@
// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs %s
// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -isystem %S/Inputs -fno-signed-char %s
#define __need_wint_t
#include <stdarg.h>
@ -530,3 +531,8 @@ void test_other_formats() {
void test_unused_system_args(int x) {
PRINT1("%d\n", x); // no-warning{{extra argument is system header is OK}}
}
void pr12761(char c) {
// This should not warn even with -fno-signed-char.
printf("%hhx", c);
}