summaryrefslogtreecommitdiffstats
path: root/test/FixIt/format-darwin.m
diff options
context:
space:
mode:
Diffstat (limited to 'test/FixIt/format-darwin.m')
-rw-r--r--test/FixIt/format-darwin.m116
1 files changed, 69 insertions, 47 deletions
diff --git a/test/FixIt/format-darwin.m b/test/FixIt/format-darwin.m
index 1bfe272..f520564 100644
--- a/test/FixIt/format-darwin.m
+++ b/test/FixIt/format-darwin.m
@@ -23,6 +23,8 @@ typedef long SInt32;
typedef unsigned long UInt32;
#endif
+typedef SInt32 OSStatus;
+
NSInteger getNSInteger();
NSUInteger getNSUInteger();
SInt32 getSInt32();
@@ -34,17 +36,17 @@ void testCorrectionInAllCases() {
printf("%s", getSInt32()); // expected-warning{{values of type 'SInt32' should not be used as format arguments; add an explicit cast to 'int' instead}}
printf("%s", getUInt32()); // expected-warning{{values of type 'UInt32' should not be used as format arguments; add an explicit cast to 'unsigned int' instead}}
- // CHECK: fix-it:"{{.*}}":{32:11-32:13}:"%ld"
- // CHECK: fix-it:"{{.*}}":{32:16-32:16}:"(long)"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:11-[[@LINE-5]]:13}:"%ld"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:16-[[@LINE-6]]:16}:"(long)"
- // CHECK: fix-it:"{{.*}}":{33:11-33:13}:"%lu"
- // CHECK: fix-it:"{{.*}}":{33:16-33:16}:"(unsigned long)"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-7]]:11-[[@LINE-7]]:13}:"%lu"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-8]]:16-[[@LINE-8]]:16}:"(unsigned long)"
- // CHECK: fix-it:"{{.*}}":{34:11-34:13}:"%d"
- // CHECK: fix-it:"{{.*}}":{34:16-34:16}:"(int)"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-9]]:11-[[@LINE-9]]:13}:"%d"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-10]]:16-[[@LINE-10]]:16}:"(int)"
- // CHECK: fix-it:"{{.*}}":{35:11-35:13}:"%u"
- // CHECK: fix-it:"{{.*}}":{35:16-35:16}:"(unsigned int)"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-11]]:11-[[@LINE-11]]:13}:"%u"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-12]]:16-[[@LINE-12]]:16}:"(unsigned int)"
}
@interface Foo {
@@ -65,7 +67,7 @@ void testParens(Foo *obj, struct Bar *record) {
NSInteger arr[4] = {0};
NSInteger i = 0;
- // These cases match the cases in CheckPrintfHandler::checkFormatExpr.
+ // These cases match the relevant cases in CheckPrintfHandler::checkFormatExpr.
printf("%s", arr[0]); // expected-warning{{values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead}}
printf("%s", getNSInteger()); // expected-warning{{values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead}}
printf("%s", i); // expected-warning{{values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead}}
@@ -80,9 +82,9 @@ void testParens(Foo *obj, struct Bar *record) {
printf("%s", i ? i : i); // expected-warning{{values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead}}
- // CHECK: fix-it:"{{.*}}":{81:11-81:13}:"%ld"
- // CHECK: fix-it:"{{.*}}":{81:16-81:16}:"(long)("
- // CHECK: fix-it:"{{.*}}":{81:25-81:25}:")"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:13}:"%ld"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:16-[[@LINE-3]]:16}:"(long)("
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:25-[[@LINE-4]]:25}:")"
}
@@ -94,28 +96,38 @@ void testWarn() {
printf("%ld", getSInt32()); // expected-warning{{values of type 'SInt32' should not be used as format arguments; add an explicit cast to 'int' instead}}
printf("%lu", getUInt32()); // expected-warning{{values of type 'UInt32' should not be used as format arguments; add an explicit cast to 'unsigned int' instead}}
- // CHECK-64: fix-it:"{{.*}}":{92:11-92:13}:"%ld"
- // CHECK-64: fix-it:"{{.*}}":{92:16-92:16}:"(long)"
+ // CHECK-64: fix-it:"{{.*}}":{[[@LINE-5]]:11-[[@LINE-5]]:13}:"%ld"
+ // CHECK-64: fix-it:"{{.*}}":{[[@LINE-6]]:16-[[@LINE-6]]:16}:"(long)"
- // CHECK-64: fix-it:"{{.*}}":{93:11-93:13}:"%lu"
- // CHECK-64: fix-it:"{{.*}}":{93:16-93:16}:"(unsigned long)"
+ // CHECK-64: fix-it:"{{.*}}":{[[@LINE-7]]:11-[[@LINE-7]]:13}:"%lu"
+ // CHECK-64: fix-it:"{{.*}}":{[[@LINE-8]]:16-[[@LINE-8]]:16}:"(unsigned long)"
- // CHECK-64: fix-it:"{{.*}}":{94:11-94:14}:"%d"
- // CHECK-64: fix-it:"{{.*}}":{94:17-94:17}:"(int)"
+ // CHECK-64: fix-it:"{{.*}}":{[[@LINE-9]]:11-[[@LINE-9]]:14}:"%d"
+ // CHECK-64: fix-it:"{{.*}}":{[[@LINE-10]]:17-[[@LINE-10]]:17}:"(int)"
- // CHECK-64: fix-it:"{{.*}}":{95:11-95:14}:"%u"
- // CHECK-64: fix-it:"{{.*}}":{95:17-95:17}:"(unsigned int)"
+ // CHECK-64: fix-it:"{{.*}}":{[[@LINE-11]]:11-[[@LINE-11]]:14}:"%u"
+ // CHECK-64: fix-it:"{{.*}}":{[[@LINE-12]]:17-[[@LINE-12]]:17}:"(unsigned int)"
}
void testPreserveHex() {
printf("%x", getNSInteger()); // expected-warning{{values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead}}
printf("%x", getNSUInteger()); // expected-warning{{values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead}}
- // CHECK-64: fix-it:"{{.*}}":{111:11-111:13}:"%lx"
- // CHECK-64: fix-it:"{{.*}}":{111:16-111:16}:"(long)"
+ // CHECK-64: fix-it:"{{.*}}":{[[@LINE-3]]:11-[[@LINE-3]]:13}:"%lx"
+ // CHECK-64: fix-it:"{{.*}}":{[[@LINE-4]]:16-[[@LINE-4]]:16}:"(long)"
+
+ // CHECK-64: fix-it:"{{.*}}":{[[@LINE-5]]:11-[[@LINE-5]]:13}:"%lx"
+ // CHECK-64: fix-it:"{{.*}}":{[[@LINE-6]]:16-[[@LINE-6]]:16}:"(unsigned long)"
+}
+
+void testSignedness(NSInteger i, NSUInteger u) {
+ printf("%d", u); // expected-warning{{values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead}}
+ printf("%i", u); // expected-warning{{values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead}}
+ printf("%u", i); // expected-warning{{values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead}}
- // CHECK-64: fix-it:"{{.*}}":{112:11-112:13}:"%lx"
- // CHECK-64: fix-it:"{{.*}}":{112:16-112:16}:"(unsigned long)"
+ // CHECK-64: fix-it:"{{.*}}":{[[@LINE-4]]:11-[[@LINE-4]]:13}:"%lu"
+ // CHECK-64: fix-it:"{{.*}}":{[[@LINE-4]]:11-[[@LINE-4]]:13}:"%lu"
+ // CHECK-64: fix-it:"{{.*}}":{[[@LINE-4]]:11-[[@LINE-4]]:13}:"%ld"
}
void testNoWarn() {
@@ -133,22 +145,18 @@ void testWarn() {
printf("%d", getSInt32()); // expected-warning{{values of type 'SInt32' should not be used as format arguments; add an explicit cast to 'int' instead}}
printf("%u", getUInt32()); // expected-warning{{values of type 'UInt32' should not be used as format arguments; add an explicit cast to 'unsigned int' instead}}
- // CHECK-32: fix-it:"{{.*}}":{131:17-131:17}:"(long)"
-
- // CHECK-32: fix-it:"{{.*}}":{132:17-132:17}:"(unsigned long)"
-
- // CHECK-32: fix-it:"{{.*}}":{133:16-133:16}:"(int)"
-
- // CHECK-32: fix-it:"{{.*}}":{134:16-134:16}:"(unsigned int)"
+ // CHECK-32: fix-it:"{{.*}}":{[[@LINE-5]]:17-[[@LINE-5]]:17}:"(long)"
+ // CHECK-32: fix-it:"{{.*}}":{[[@LINE-5]]:17-[[@LINE-5]]:17}:"(unsigned long)"
+ // CHECK-32: fix-it:"{{.*}}":{[[@LINE-5]]:16-[[@LINE-5]]:16}:"(int)"
+ // CHECK-32: fix-it:"{{.*}}":{[[@LINE-5]]:16-[[@LINE-5]]:16}:"(unsigned int)"
}
void testPreserveHex() {
printf("%lx", getNSInteger()); // expected-warning{{values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead}}
printf("%lx", getNSUInteger()); // expected-warning{{values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead}}
- // CHECK-32: fix-it:"{{.*}}":{146:17-146:17}:"(long)"
-
- // CHECK-32: fix-it:"{{.*}}":{147:17-147:17}:"(unsigned long)"
+ // CHECK-32: fix-it:"{{.*}}":{[[@LINE-3]]:17-[[@LINE-3]]:17}:"(long)"
+ // CHECK-32: fix-it:"{{.*}}":{[[@LINE-3]]:17-[[@LINE-3]]:17}:"(unsigned long)"
}
void testNoWarn() {
@@ -158,6 +166,14 @@ void testNoWarn() {
printf("%lu", getUInt32()); // no-warning
}
+void testSignedness(NSInteger i, NSUInteger u) {
+ // It is valid to use a specifier with the opposite signedness as long as
+ // the type is correct.
+ printf("%d", u); // no-warning
+ printf("%i", u); // no-warning
+ printf("%u", i); // no-warning
+}
+
#endif
@@ -167,17 +183,17 @@ void testCasts() {
printf("%s", (SInt32)0); // expected-warning{{values of type 'SInt32' should not be used as format arguments; add an explicit cast to 'int' instead}}
printf("%s", (UInt32)0); // expected-warning{{values of type 'UInt32' should not be used as format arguments; add an explicit cast to 'unsigned int' instead}}
- // CHECK: fix-it:"{{.*}}":{165:11-165:13}:"%ld"
- // CHECK: fix-it:"{{.*}}":{165:16-165:27}:"(long)"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-5]]:11-[[@LINE-5]]:13}:"%ld"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-6]]:16-[[@LINE-6]]:27}:"(long)"
- // CHECK: fix-it:"{{.*}}":{166:11-166:13}:"%lu"
- // CHECK: fix-it:"{{.*}}":{166:16-166:28}:"(unsigned long)"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-7]]:11-[[@LINE-7]]:13}:"%lu"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-8]]:16-[[@LINE-8]]:28}:"(unsigned long)"
- // CHECK: fix-it:"{{.*}}":{167:11-167:13}:"%d"
- // CHECK: fix-it:"{{.*}}":{167:16-167:24}:"(int)"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-9]]:11-[[@LINE-9]]:13}:"%d"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-10]]:16-[[@LINE-10]]:24}:"(int)"
- // CHECK: fix-it:"{{.*}}":{168:11-168:13}:"%u"
- // CHECK: fix-it:"{{.*}}":{168:16-168:24}:"(unsigned int)"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-11]]:11-[[@LINE-11]]:13}:"%u"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-12]]:16-[[@LINE-12]]:24}:"(unsigned int)"
}
void testCapitals() {
@@ -185,14 +201,20 @@ void testCapitals() {
printf("%U", 1); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'u'?}}
printf("%O", 1); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'o'?}}
- // CHECK: fix-it:"{{.*}}":{184:12-184:13}:"d"
- // CHECK: fix-it:"{{.*}}":{185:12-185:13}:"u"
- // CHECK: fix-it:"{{.*}}":{186:12-186:13}:"o"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:12-[[@LINE-4]]:13}:"d"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:12-[[@LINE-4]]:13}:"u"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:12-[[@LINE-4]]:13}:"o"
printf("%lD", 1); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'd'?}} expected-warning{{format specifies type 'long' but the argument has type 'int'}}
// FIXME: offering two somewhat-conflicting fixits is less than ideal.
- // CHECK: fix-it:"{{.*}}":{193:13-193:14}:"d"
- // CHECK: fix-it:"{{.*}}":{193:11-193:14}:"%D"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:13-[[@LINE-3]]:14}:"d"
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:11-[[@LINE-4]]:14}:"%D"
}
+
+void testLayeredTypedefs(OSStatus i) {
+ printf("%s", i); // expected-warning {{values of type 'OSStatus' should not be used as format arguments}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%d"
+}
+
OpenPOWER on IntegriCloud