summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2012-12-05 18:44:37 +0000
committerJordan Rose <jordan_rose@apple.com>2012-12-05 18:44:37 +0000
commit6aaa87e0d27b42d1d7a95c8591b57fc5b3725fb0 (patch)
tree1fc2174aeb661488ecbeedb2cfba68f86fc39e66 /clang
parent507aca835ea2bf1735e2f89a0904d6f6d0dfdd40 (diff)
downloadbcm5719-llvm-6aaa87e0d27b42d1d7a95c8591b57fc5b3725fb0.tar.gz
bcm5719-llvm-6aaa87e0d27b42d1d7a95c8591b57fc5b3725fb0.zip
Format strings: the correct conversion for 'char' is %c, not %d or %hhd.
We tried to account for 'uint8_t' by saying that /typedefs/ of 'char' should be corrected as %hhd rather than %c, but the condition was wrong. llvm-svn: 169397
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Analysis/PrintfFormatString.cpp2
-rw-r--r--clang/test/FixIt/format.m54
2 files changed, 55 insertions, 1 deletions
diff --git a/clang/lib/Analysis/PrintfFormatString.cpp b/clang/lib/Analysis/PrintfFormatString.cpp
index 611815cd89e..08207910b83 100644
--- a/clang/lib/Analysis/PrintfFormatString.cpp
+++ b/clang/lib/Analysis/PrintfFormatString.cpp
@@ -506,7 +506,7 @@ bool PrintfSpecifier::fixType(QualType QT, const LangOptions &LangOpt,
// Set conversion specifier and disable any flags which do not apply to it.
// Let typedefs to char fall through to int, as %c is silly for uint8_t.
- if (isa<TypedefType>(QT) && QT->isAnyCharacterType()) {
+ if (!isa<TypedefType>(QT) && QT->isCharType()) {
CS.setKind(ConversionSpecifier::cArg);
LM.setKind(LengthModifier::None);
Precision.setHowSpecified(OptionalAmount::NotSpecified);
diff --git a/clang/test/FixIt/format.m b/clang/test/FixIt/format.m
index c4747019b2d..4b13c2cf956 100644
--- a/clang/test/FixIt/format.m
+++ b/clang/test/FixIt/format.m
@@ -93,3 +93,57 @@ void test_named_fixed_enum_correction(enum SomeSize x) {
// CHECK: fix-it:"{{.*}}":{92:11-92:13}:"%zu"
}
+
+typedef unsigned char uint8_t;
+void test_char(char c, signed char s, unsigned char u, uint8_t n) {
+ NSLog(@"%s", c); // expected-warning{{format specifies type 'char *' but the argument has type 'char'}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
+
+ NSLog(@"%lf", c); // expected-warning{{format specifies type 'double' but the argument has type 'char'}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%c"
+
+ NSLog(@"%@", c); // expected-warning{{format specifies type 'id' but the argument has type 'char'}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
+
+ NSLog(@"%c", c); // no-warning
+ // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
+
+
+ NSLog(@"%s", s); // expected-warning{{format specifies type 'char *' but the argument has type 'signed char'}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
+
+ NSLog(@"%lf", s); // expected-warning{{format specifies type 'double' but the argument has type 'signed char'}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%c"
+
+ NSLog(@"%@", s); // expected-warning{{format specifies type 'id' but the argument has type 'signed char'}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
+
+ NSLog(@"%c", s); // no-warning
+ // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
+
+
+ NSLog(@"%s", u); // expected-warning{{format specifies type 'char *' but the argument has type 'unsigned char'}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
+
+ NSLog(@"%lf", u); // expected-warning{{format specifies type 'double' but the argument has type 'unsigned char'}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%c"
+
+ NSLog(@"%@", u); // expected-warning{{format specifies type 'id' but the argument has type 'unsigned char'}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
+
+ NSLog(@"%c", u); // no-warning
+ // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
+
+
+ NSLog(@"%s", n); // expected-warning{{format specifies type 'char *' but the argument has type 'uint8_t' (aka 'unsigned char')}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%hhu"
+
+ NSLog(@"%lf", n); // expected-warning{{format specifies type 'double' but the argument has type 'uint8_t' (aka 'unsigned char')}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%hhu"
+
+ NSLog(@"%@", n); // expected-warning{{format specifies type 'id' but the argument has type 'uint8_t' (aka 'unsigned char')}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%hhu"
+
+ NSLog(@"%c", n); // no-warning
+ // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%hhu"
+}
OpenPOWER on IntegriCloud