]> granicus.if.org Git - clang/commitdiff
Fix inversion in argument type checking for format strings with conversion specifiers...
authorTed Kremenek <kremenek@apple.com>
Wed, 13 Jul 2011 17:25:47 +0000 (17:25 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 13 Jul 2011 17:25:47 +0000 (17:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135046 91177308-0d34-0410-b5e6-96231b3b80d8

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

index c1b5ea8a652a7c4849fb76358ae2d0a12d46e266..9a8639015c0fb5273545da549472dec952a6a081 100644 (file)
@@ -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:
index 35210c341a524fb3295daa9e21e944331878f6f2..83f96ff3a00f02275db81bb13229b9721f0efe87 100644 (file)
@@ -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'}}
+}