diff options
author | Alexander Shaposhnikov <shal1t712@gmail.com> | 2017-06-26 23:02:27 +0000 |
---|---|---|
committer | Alexander Shaposhnikov <shal1t712@gmail.com> | 2017-06-26 23:02:27 +0000 |
commit | 623513742c068bf463e8287d91ba42bc2fe2e3ef (patch) | |
tree | cbc98738c00ddba3045fa9f104a242df256d354c /clang/test/FixIt/format-darwin.m | |
parent | 01676883cd6b4016c3d4b8cc2761f6a1f3ea2ea2 (diff) | |
download | bcm5719-llvm-623513742c068bf463e8287d91ba42bc2fe2e3ef.tar.gz bcm5719-llvm-623513742c068bf463e8287d91ba42bc2fe2e3ef.zip |
[clang] Enable printf check for CFIndex
According to
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html
CFIndex and NSInteger should be treated the same way (see the section Platform Dependencies).
This diff changes the function shouldNotPrintDirectly in SemaChecking.cpp accordingly
and adds tests for the "fixit" and the warning.
Differential revision: https://reviews.llvm.org/D34496
Test plan: make check-all
llvm-svn: 306343
Diffstat (limited to 'clang/test/FixIt/format-darwin.m')
-rw-r--r-- | clang/test/FixIt/format-darwin.m | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/clang/test/FixIt/format-darwin.m b/clang/test/FixIt/format-darwin.m index 170bb09fb90..fcc81036fcf 100644 --- a/clang/test/FixIt/format-darwin.m +++ b/clang/test/FixIt/format-darwin.m @@ -7,13 +7,14 @@ int printf(const char * restrict, ...); #if __LP64__ +typedef long CFIndex; typedef long NSInteger; typedef unsigned long NSUInteger; typedef int SInt32; typedef unsigned int UInt32; #else - +typedef int CFIndex; typedef int NSInteger; typedef unsigned int NSUInteger; typedef long SInt32; @@ -27,6 +28,7 @@ typedef enum NSIntegerEnum : NSInteger { EnumValueB } NSIntegerEnum; +CFIndex getCFIndex(); NSInteger getNSInteger(); NSUInteger getNSUInteger(); SInt32 getSInt32(); @@ -55,6 +57,11 @@ void testCorrectionInAllCases() { // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:13}:"%ld" // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:16-[[@LINE-3]]:16}:"(long)" + + printf("%s", getCFIndex()); // expected-warning{{values of type 'CFIndex' should not be used as format arguments; add an explicit cast to 'long' instead}} + + // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:13}:"%ld" + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:16-[[@LINE-3]]:16}:"(long)" } @interface Foo { @@ -120,6 +127,11 @@ void testWarn() { // CHECK-64: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:13}:"%ld" // CHECK-64: fix-it:"{{.*}}":{[[@LINE-3]]:16-[[@LINE-3]]:16}:"(long)" + + printf("%d", getCFIndex()); // expected-warning{{values of type 'CFIndex' should not be used as format arguments; add an explicit cast to 'long' instead}} + + // CHECK-64: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:13}:"%ld" + // CHECK-64: fix-it:"{{.*}}":{[[@LINE-3]]:16-[[@LINE-3]]:16}:"(long)" } void testPreserveHex() { @@ -167,6 +179,10 @@ void testWarn() { printf("%ld", getNSIntegerEnum()); // expected-warning{{enum values with underlying type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead}} // CHECK-32: fix-it:"{{.*}}":{[[@LINE-2]]:17-[[@LINE-2]]:17}:"(long)" + + printf("%ld", getCFIndex()); // expected-warning{{values of type 'CFIndex' should not be used as format arguments; add an explicit cast to 'long' instead}} + + // CHECK-32: fix-it:"{{.*}}":{[[@LINE-2]]:17-[[@LINE-2]]:17}:"(long)" } void testPreserveHex() { @@ -218,6 +234,11 @@ void testCasts() { // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:13}:"%ld" // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:16-[[@LINE-3]]:31}:"(long)" + + printf("%s", (CFIndex)0); // expected-warning{{values of type 'CFIndex' should not be used as format arguments; add an explicit cast to 'long' instead}} + + // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:13}:"%ld" + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:16-[[@LINE-3]]:25}:"(long)" } void testCapitals() { |