[PATCH] D148779: [Sema] Fix spurious warning for printf("%lb", (long)10)
Fangrui Song via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 19 20:39:45 PDT 2023
MaskRay updated this revision to Diff 515205.
MaskRay added a comment.
update test/Sema/format-strings-fixit.c
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D148779/new/
https://reviews.llvm.org/D148779
Files:
clang/lib/AST/FormatString.cpp
clang/test/Sema/format-strings-fixit.c
clang/test/Sema/format-strings.c
Index: clang/test/Sema/format-strings.c
===================================================================
--- clang/test/Sema/format-strings.c
+++ clang/test/Sema/format-strings.c
@@ -304,6 +304,7 @@
printf("%qp", (void *)0); // expected-warning{{length modifier 'q' results in undefined behavior or no effect with 'p' conversion specifier}}
printf("hhX %hhX", (unsigned char)10); // no-warning
printf("llX %llX", (long long) 10); // no-warning
+ printf("%lb %lB", (long) 10, (long) 10); // no-warning
printf("%llb %llB", (long long) 10, (long long) 10); // no-warning
// This is fine, because there is an implicit conversion to an int.
printf("%d", (unsigned char) 10); // no-warning
Index: clang/test/Sema/format-strings-fixit.c
===================================================================
--- clang/test/Sema/format-strings-fixit.c
+++ clang/test/Sema/format-strings-fixit.c
@@ -22,6 +22,7 @@
printf("abc%0f", "testing testing 123");
printf("%u", (long) -12);
printf("%b", (long) -13);
+ printf("%d", (long) -14);
printf("%p", 123);
printf("%c\n", "x");
printf("%c\n", 1.23);
@@ -162,6 +163,7 @@
// Preserve the original formatting.
scanf("%b", &longVar);
+ scanf("%d", &longVar);
scanf("%o", &longVar);
scanf("%u", &longVar);
scanf("%x", &longVar);
@@ -181,7 +183,8 @@
// CHECK: printf("%d", (int) 123);
// CHECK: printf("abc%s", "testing testing 123");
// CHECK: printf("%ld", (long) -12);
-// CHECK: printf("%ld", (long) -13);
+// CHECK: printf("%lb", (long) -13);
+// CHECK: printf("%ld", (long) -14);
// CHECK: printf("%d", 123);
// CHECK: printf("%s\n", "x");
// CHECK: printf("%f\n", 1.23);
@@ -249,6 +252,7 @@
// CHECK: scanf("%ju", (my_uintmax_type*)&uIntmaxVar);
// CHECK: scanf("%td", (my_ptrdiff_type*)&ptrdiffVar);
// CHECK: scanf("%d", (my_int_type*)&intVar);
+// CHECK: scanf("%lb", &longVar);
// CHECK: scanf("%ld", &longVar);
// CHECK: scanf("%lo", &longVar);
// CHECK: scanf("%lu", &longVar);
Index: clang/lib/AST/FormatString.cpp
===================================================================
--- clang/lib/AST/FormatString.cpp
+++ clang/lib/AST/FormatString.cpp
@@ -848,6 +848,8 @@
}
switch (CS.getKind()) {
+ case ConversionSpecifier::bArg:
+ case ConversionSpecifier::BArg:
case ConversionSpecifier::dArg:
case ConversionSpecifier::DArg:
case ConversionSpecifier::iArg:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148779.515205.patch
Type: text/x-patch
Size: 2434 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230420/fe070517/attachment.bin>
More information about the cfe-commits
mailing list