[PATCH] D35427: [clang] Fix handling of "%zd" format specifier
hans added a comment. Thanks for fixing this long-standing TODO :-) Repository: rL LLVM https://reviews.llvm.org/D35427 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D35427: [clang] Fix handling of "%zd" format specifier
alexshap added a comment. @chapuni - many thanks! Repository: rL LLVM https://reviews.llvm.org/D35427 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D35427: [clang] Fix handling of "%zd" format specifier
chapuni added inline comments. Comment at: cfe/trunk/test/FixIt/format.m:240 + int x; + printf("%zn", &x); // expected-warning{{format specifies type 'ssize_t *' (aka 'long *') but the argument has type 'int *'}} + // PrintfSpecifier::fixType doesn't handle %n, so a fix-it is not emitted, The warning wasn't emitted since ssize_t is int for targeting i686. Tweaked in rL308084. File clang/test/FixIt/format.m Line 240: format specifies type 'ssize_t *' (aka 'int *') but the argument has type 'short *' Repository: rL LLVM https://reviews.llvm.org/D35427 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D35427: [clang] Fix handling of "%zd" format specifier
This revision was automatically updated to reflect the committed changes. Closed by commit rL308067: [clang] Fix handling of "%zd" format specifier (authored by alexshap). Changed prior to commit: https://reviews.llvm.org/D35427?vs=106694&id=106726#toc Repository: rL LLVM https://reviews.llvm.org/D35427 Files: cfe/trunk/lib/Analysis/PrintfFormatString.cpp cfe/trunk/test/FixIt/format.m Index: cfe/trunk/lib/Analysis/PrintfFormatString.cpp === --- cfe/trunk/lib/Analysis/PrintfFormatString.cpp +++ cfe/trunk/lib/Analysis/PrintfFormatString.cpp @@ -466,8 +466,7 @@ case LengthModifier::AsIntMax: return ArgType(Ctx.getIntMaxType(), "intmax_t"); case LengthModifier::AsSizeT: -// FIXME: How to get the corresponding signed version of size_t? -return ArgType(); +return ArgType(Ctx.getSignedSizeType(), "ssize_t"); case LengthModifier::AsInt3264: return Ctx.getTargetInfo().getTriple().isArch64Bit() ? ArgType(Ctx.LongLongTy, "__int64") @@ -537,7 +536,7 @@ case LengthModifier::AsIntMax: return ArgType::PtrTo(ArgType(Ctx.getIntMaxType(), "intmax_t")); case LengthModifier::AsSizeT: -return ArgType(); // FIXME: ssize_t +return ArgType::PtrTo(ArgType(Ctx.getSignedSizeType(), "ssize_t")); case LengthModifier::AsPtrDiff: return ArgType::PtrTo(ArgType(Ctx.getPointerDiffType(), "ptrdiff_t")); case LengthModifier::AsLongDouble: Index: cfe/trunk/test/FixIt/format.m === --- cfe/trunk/test/FixIt/format.m +++ cfe/trunk/test/FixIt/format.m @@ -229,6 +229,19 @@ // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:14}:"%+ld" } +void testSizeTypes() { + printf("%zu", 0.f); // expected-warning{{format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'float'}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f" + + printf("%zd", 0.f); // expected-warning{{format specifies type 'ssize_t' (aka 'long') but the argument has type 'float'}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f" + + int x; + printf("%zn", &x); // expected-warning{{format specifies type 'ssize_t *' (aka 'long *') but the argument has type 'int *'}} + // 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, Index: cfe/trunk/lib/Analysis/PrintfFormatString.cpp === --- cfe/trunk/lib/Analysis/PrintfFormatString.cpp +++ cfe/trunk/lib/Analysis/PrintfFormatString.cpp @@ -466,8 +466,7 @@ case LengthModifier::AsIntMax: return ArgType(Ctx.getIntMaxType(), "intmax_t"); case LengthModifier::AsSizeT: -// FIXME: How to get the corresponding signed version of size_t? -return ArgType(); +return ArgType(Ctx.getSignedSizeType(), "ssize_t"); case LengthModifier::AsInt3264: return Ctx.getTargetInfo().getTriple().isArch64Bit() ? ArgType(Ctx.LongLongTy, "__int64") @@ -537,7 +536,7 @@ case LengthModifier::AsIntMax: return ArgType::PtrTo(ArgType(Ctx.getIntMaxType(), "intmax_t")); case LengthModifier::AsSizeT: -return ArgType(); // FIXME: ssize_t +return ArgType::PtrTo(ArgType(Ctx.getSignedSizeType(), "ssize_t")); case LengthModifier::AsPtrDiff: return ArgType::PtrTo(ArgType(Ctx.getPointerDiffType(), "ptrdiff_t")); case LengthModifier::AsLongDouble: Index: cfe/trunk/test/FixIt/format.m === --- cfe/trunk/test/FixIt/format.m +++ cfe/trunk/test/FixIt/format.m @@ -229,6 +229,19 @@ // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:14}:"%+ld" } +void testSizeTypes() { + printf("%zu", 0.f); // expected-warning{{format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'float'}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f" + + printf("%zd", 0.f); // expected-warning{{format specifies type 'ssize_t' (aka 'long') but the argument has type 'float'}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f" + + int x; + printf("%zn", &x); // expected-warning{{format specifies type 'ssize_t *' (aka 'long *') but the argument has type 'int *'}} + // 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, ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D35427: [clang] Fix handling of "%zd" format specifier
aaron.ballman accepted this revision. aaron.ballman added a comment. This revision is now accepted and ready to land. LGTM! Repository: rL LLVM https://reviews.llvm.org/D35427 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D35427: [clang] Fix handling of "%zd" format specifier
alexshap updated this revision to Diff 106694. alexshap added a comment. Address comments Repository: rL LLVM https://reviews.llvm.org/D35427 Files: lib/Analysis/PrintfFormatString.cpp test/FixIt/format.m Index: test/FixIt/format.m === --- test/FixIt/format.m +++ test/FixIt/format.m @@ -229,6 +229,19 @@ // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:14}:"%+ld" } +void testSizeTypes() { + printf("%zu", 0.f); // expected-warning{{format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'float'}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f" + + printf("%zd", 0.f); // expected-warning{{format specifies type 'ssize_t' (aka 'long') but the argument has type 'float'}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f" + + int x; + printf("%zn", &x); // expected-warning{{format specifies type 'ssize_t *' (aka 'long *') but the argument has type 'int *'}} + // 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, Index: lib/Analysis/PrintfFormatString.cpp === --- lib/Analysis/PrintfFormatString.cpp +++ lib/Analysis/PrintfFormatString.cpp @@ -466,8 +466,7 @@ case LengthModifier::AsIntMax: return ArgType(Ctx.getIntMaxType(), "intmax_t"); case LengthModifier::AsSizeT: -// FIXME: How to get the corresponding signed version of size_t? -return ArgType(); +return ArgType(Ctx.getSignedSizeType(), "ssize_t"); case LengthModifier::AsInt3264: return Ctx.getTargetInfo().getTriple().isArch64Bit() ? ArgType(Ctx.LongLongTy, "__int64") @@ -537,7 +536,7 @@ case LengthModifier::AsIntMax: return ArgType::PtrTo(ArgType(Ctx.getIntMaxType(), "intmax_t")); case LengthModifier::AsSizeT: -return ArgType(); // FIXME: ssize_t +return ArgType::PtrTo(ArgType(Ctx.getSignedSizeType(), "ssize_t")); case LengthModifier::AsPtrDiff: return ArgType::PtrTo(ArgType(Ctx.getPointerDiffType(), "ptrdiff_t")); case LengthModifier::AsLongDouble: Index: test/FixIt/format.m === --- test/FixIt/format.m +++ test/FixIt/format.m @@ -229,6 +229,19 @@ // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:14}:"%+ld" } +void testSizeTypes() { + printf("%zu", 0.f); // expected-warning{{format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'float'}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f" + + printf("%zd", 0.f); // expected-warning{{format specifies type 'ssize_t' (aka 'long') but the argument has type 'float'}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f" + + int x; + printf("%zn", &x); // expected-warning{{format specifies type 'ssize_t *' (aka 'long *') but the argument has type 'int *'}} + // 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, Index: lib/Analysis/PrintfFormatString.cpp === --- lib/Analysis/PrintfFormatString.cpp +++ lib/Analysis/PrintfFormatString.cpp @@ -466,8 +466,7 @@ case LengthModifier::AsIntMax: return ArgType(Ctx.getIntMaxType(), "intmax_t"); case LengthModifier::AsSizeT: -// FIXME: How to get the corresponding signed version of size_t? -return ArgType(); +return ArgType(Ctx.getSignedSizeType(), "ssize_t"); case LengthModifier::AsInt3264: return Ctx.getTargetInfo().getTriple().isArch64Bit() ? ArgType(Ctx.LongLongTy, "__int64") @@ -537,7 +536,7 @@ case LengthModifier::AsIntMax: return ArgType::PtrTo(ArgType(Ctx.getIntMaxType(), "intmax_t")); case LengthModifier::AsSizeT: -return ArgType(); // FIXME: ssize_t +return ArgType::PtrTo(ArgType(Ctx.getSignedSizeType(), "ssize_t")); case LengthModifier::AsPtrDiff: return ArgType::PtrTo(ArgType(Ctx.getPointerDiffType(), "ptrdiff_t")); case LengthModifier::AsLongDouble: ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D35427: [clang] Fix handling of "%zd" format specifier
aaron.ballman added a reviewer: aaron.ballman. aaron.ballman added inline comments. Comment at: lib/Analysis/PrintfFormatString.cpp:539 case LengthModifier::AsSizeT: return ArgType(); // FIXME: ssize_t case LengthModifier::AsPtrDiff: What about here? Repository: rL LLVM https://reviews.llvm.org/D35427 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D35427: [clang] Fix handling of "%zd" format specifier
alexshap created this revision. This diff addresses FIXME in lib/Analysis/PrintfFormatString.cpp and makes Clang warn on incorrect using of "%zd" format specifier. Test plan: make check-all Repository: rL LLVM https://reviews.llvm.org/D35427 Files: lib/Analysis/PrintfFormatString.cpp test/FixIt/format.m Index: test/FixIt/format.m === --- test/FixIt/format.m +++ test/FixIt/format.m @@ -229,6 +229,13 @@ // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:14}:"%+ld" } +void testSizeTypes() { + printf("%zu", 0.f); // expected-warning{{format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'float'}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f" + printf("%zd", 0.f); // expected-warning{{format specifies type 'ssize_t' (aka 'long') but the argument has type 'float'}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f" +} + void testEnum() { typedef enum { ImplicitA = 1, Index: lib/Analysis/PrintfFormatString.cpp === --- lib/Analysis/PrintfFormatString.cpp +++ lib/Analysis/PrintfFormatString.cpp @@ -466,8 +466,7 @@ case LengthModifier::AsIntMax: return ArgType(Ctx.getIntMaxType(), "intmax_t"); case LengthModifier::AsSizeT: -// FIXME: How to get the corresponding signed version of size_t? -return ArgType(); +return ArgType(Ctx.getSignedSizeType(), "ssize_t"); case LengthModifier::AsInt3264: return Ctx.getTargetInfo().getTriple().isArch64Bit() ? ArgType(Ctx.LongLongTy, "__int64") Index: test/FixIt/format.m === --- test/FixIt/format.m +++ test/FixIt/format.m @@ -229,6 +229,13 @@ // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:14}:"%+ld" } +void testSizeTypes() { + printf("%zu", 0.f); // expected-warning{{format specifies type 'size_t' (aka 'unsigned long') but the argument has type 'float'}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f" + printf("%zd", 0.f); // expected-warning{{format specifies type 'ssize_t' (aka 'long') but the argument has type 'float'}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%f" +} + void testEnum() { typedef enum { ImplicitA = 1, Index: lib/Analysis/PrintfFormatString.cpp === --- lib/Analysis/PrintfFormatString.cpp +++ lib/Analysis/PrintfFormatString.cpp @@ -466,8 +466,7 @@ case LengthModifier::AsIntMax: return ArgType(Ctx.getIntMaxType(), "intmax_t"); case LengthModifier::AsSizeT: -// FIXME: How to get the corresponding signed version of size_t? -return ArgType(); +return ArgType(Ctx.getSignedSizeType(), "ssize_t"); case LengthModifier::AsInt3264: return Ctx.getTargetInfo().getTriple().isArch64Bit() ? ArgType(Ctx.LongLongTy, "__int64") ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits