]> granicus.if.org Git - clang/commitdiff
Make -Wformat accept printf("%hhx", c); with -funsigned-char
authorHans Wennborg <hans@hanshq.net>
Tue, 8 May 2012 17:21:31 +0000 (17:21 +0000)
committerHans Wennborg <hans@hanshq.net>
Tue, 8 May 2012 17:21:31 +0000 (17:21 +0000)
For "%hhx", printf expects an unsigned char. This makes Clang
accept a 'char' argument for that also when using -funsigned-char.

This fixes PR12761.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156388 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/FormatString.cpp
test/Sema/format-strings.c

index ab69c069114b3242eb2d87573e5dbf0d20809a6d..f776c89cc5610b3ee5a59cca9cdd4b8e35a48ecf 100644 (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:
index 5d8e4cbb874ca50fef7f34f48aa38a907e426d66..1f9acd4ef8193aa6cc668b6730fcb0005ec06b38 100644 (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);
+}