summaryrefslogtreecommitdiffstats
path: root/clang/test/FixIt
diff options
context:
space:
mode:
authorAlexander Shaposhnikov <shal1t712@gmail.com>2017-09-28 23:11:31 +0000
committerAlexander Shaposhnikov <shal1t712@gmail.com>2017-09-28 23:11:31 +0000
commit195b25cf3cbde92e8613465571b5f3511c5cc69d (patch)
tree5e3ab1261aa73902302fe2e178ef81f5b939a099 /clang/test/FixIt
parentef29a84d4890e00abdf1892f67a431e2624f89ec (diff)
downloadbcm5719-llvm-195b25cf3cbde92e8613465571b5f3511c5cc69d.tar.gz
bcm5719-llvm-195b25cf3cbde92e8613465571b5f3511c5cc69d.zip
[clang] Add getUnsignedPointerDiffType method
C11 standard refers to the unsigned counterpart of the type ptrdiff_t in the paragraph 7.21.6.1p7 where it defines the format specifier %tu. In Clang (in PrintfFormatString.cpp, lines 508-510) there is a FIXME for this case, in particular, Clang didn't diagnose %tu issues at all, i.e. it didn't emit any warnings on the code printf("%tu", 3.14). In this diff we add a method getUnsignedPointerDiffType for getting the corresponding type similarly to how it's already done in the other analogous cases (size_t, ssize_t, ptrdiff_t etc) and fix -Wformat diagnostics for %tu plus the emitted fix-it as well. Test plan: make check-all Differential revision: https://reviews.llvm.org/D38270 llvm-svn: 314470
Diffstat (limited to 'clang/test/FixIt')
-rw-r--r--clang/test/FixIt/format.m31
1 files changed, 31 insertions, 0 deletions
diff --git a/clang/test/FixIt/format.m b/clang/test/FixIt/format.m
index c3cf2b1f3c5..40655a0e808 100644
--- a/clang/test/FixIt/format.m
+++ b/clang/test/FixIt/format.m
@@ -242,6 +242,37 @@ void testSizeTypes() {
// see the comment in PrintfSpecifier::fixType in PrintfFormatString.cpp.
}
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+#define __UNSIGNED_PTRDIFF_TYPE__ \
+ __typeof__(_Generic((__PTRDIFF_TYPE__)0, \
+ long long int : (unsigned long long int)0, \
+ long int : (unsigned long int)0, \
+ int : (unsigned int)0, \
+ short : (unsigned short)0, \
+ signed char : (unsigned char)0))
+
+void testPtrDiffTypes() {
+ __UNSIGNED_PTRDIFF_TYPE__ p1 = 0;
+ printf("%tu", p1); // No warning.
+
+ printf("%tu", 0.f); // expected-warning-re{{format specifies type 'unsigned ptrdiff_t' (aka '{{.+}}') but the argument has type 'float'}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f"
+
+ ptrdiff_t p2 = 0;
+ printf("%td", p2); // No warning.
+
+ printf("%td", 0.f); // expected-warning-re{{format specifies type 'ptrdiff_t' (aka '{{.+}}') but the argument has type 'float'}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f"
+
+ ptrdiff_t p3 = 0;
+ printf("%tn", &p3); // No warning.
+
+ short x;
+ printf("%tn", &x); // expected-warning-re{{format specifies type 'ptrdiff_t *' (aka '{{.+}}') but the argument has type 'short *'}}
+ // PrintfSpecifier::fixType doesn't handle %n, so a fix-it is not emitted,
+ // see the comment in PrintfSpecifier::fixType in PrintfFormatString.cpp.
+}
+
void testEnum() {
typedef enum {
ImplicitA = 1,
OpenPOWER on IntegriCloud