[cfe-commits] r135046 - in /cfe/trunk: lib/Analysis/FormatString.cpp test/Sema/format-strings.c

Ted Kremenek kremenek at apple.com
Wed Jul 13 10:25:47 PDT 2011


Author: kremenek
Date: Wed Jul 13 12:25:47 2011
New Revision: 135046

URL: http://llvm.org/viewvc/llvm-project?rev=135046&view=rev
Log:
Fix inversion in argument type checking for format strings with conversion specifiers for character types.

Modified:
    cfe/trunk/lib/Analysis/FormatString.cpp
    cfe/trunk/test/Sema/format-strings.c

Modified: cfe/trunk/lib/Analysis/FormatString.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/FormatString.cpp?rev=135046&r1=135045&r2=135046&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/FormatString.cpp (original)
+++ cfe/trunk/lib/Analysis/FormatString.cpp Wed Jul 13 12:25:47 2011
@@ -225,10 +225,10 @@
             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:

Modified: cfe/trunk/test/Sema/format-strings.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/format-strings.c?rev=135046&r1=135045&r2=135046&view=diff
==============================================================================
--- cfe/trunk/test/Sema/format-strings.c (original)
+++ cfe/trunk/test/Sema/format-strings.c Wed Jul 13 12:25:47 2011
@@ -363,3 +363,12 @@
 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'}}
+}





More information about the cfe-commits mailing list