[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:32:05 PDT 2023


MaskRay created this revision.
MaskRay added reviewers: aaron.ballman, dim, enh.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fix https://github.com/llvm/llvm-project/issues/62247

D131057 <https://reviews.llvm.org/D131057> added `bArg` and `BArg` in the `AsLongLong` label in
`FormatSpecifier::hasValidLengthModifier`, but missed the `AsLong` label,
therefore `%llb` is allowed while `%lb` has a spurious warning.
Add the missing case labels.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148779

Files:
  clang/lib/AST/FormatString.cpp
  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/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.515202.patch
Type: text/x-patch
Size: 1149 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230420/3b998cf6/attachment.bin>


More information about the cfe-commits mailing list