[clang] 1e86d63 - [clang] Selectively ena/disa-ble format-insufficient-args warning

Jan Korous via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 28 16:25:06 PDT 2020


Author: Jan Korous
Date: 2020-09-28T16:24:50-07:00
New Revision: 1e86d637eb4f88e03fcd4b9fd78192487dc2a302

URL: https://github.com/llvm/llvm-project/commit/1e86d637eb4f88e03fcd4b9fd78192487dc2a302
DIFF: https://github.com/llvm/llvm-project/commit/1e86d637eb4f88e03fcd4b9fd78192487dc2a302.diff

LOG: [clang] Selectively ena/disa-ble format-insufficient-args warning

Differential Revision: https://reviews.llvm.org/D87176

Added: 
    clang/test/Sema/warn-printf-insufficient-data-args.c

Modified: 
    clang/include/clang/Basic/DiagnosticGroups.td
    clang/include/clang/Basic/DiagnosticSemaKinds.td
    clang/test/Misc/warning-wall.c

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index a2f5aeafd457..d8e66bdefca1 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -239,6 +239,7 @@ def ExtraSemi : DiagGroup<"extra-semi", [CXX98CompatExtraSemi,
 def GNUFlexibleArrayInitializer : DiagGroup<"gnu-flexible-array-initializer">;
 def GNUFlexibleArrayUnionMember : DiagGroup<"gnu-flexible-array-union-member">;
 def GNUFoldingConstant : DiagGroup<"gnu-folding-constant">;
+def FormatInsufficientArgs : DiagGroup<"format-insufficient-args">;
 def FormatExtraArgs : DiagGroup<"format-extra-args">;
 def FormatZeroLength : DiagGroup<"format-zero-length">;
 
@@ -849,7 +850,8 @@ def FormatPedantic : DiagGroup<"format-pedantic">;
 def FormatTypeConfusion : DiagGroup<"format-type-confusion">;
 def Format : DiagGroup<"format",
                        [FormatExtraArgs, FormatZeroLength, NonNull,
-                        FormatSecurity, FormatY2K, FormatInvalidSpecifier]>,
+                        FormatSecurity, FormatY2K, FormatInvalidSpecifier,
+                        FormatInsufficientArgs]>,
              DiagCategory<"Format String Issue">;
 def FormatNonLiteral : DiagGroup<"format-nonliteral">;
 def Format2 : DiagGroup<"format=2",

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0cb817df9db3..42d50426ccd8 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8921,7 +8921,7 @@ def note_array_declared_here : Note<
   "array %0 declared here">;
 
 def warn_printf_insufficient_data_args : Warning<
-  "more '%%' conversions than data arguments">, InGroup<Format>;
+  "more '%%' conversions than data arguments">, InGroup<FormatInsufficientArgs>;
 def warn_printf_data_arg_not_used : Warning<
   "data argument not used by format string">, InGroup<FormatExtraArgs>;
 def warn_format_invalid_conversion : Warning<

diff  --git a/clang/test/Misc/warning-wall.c b/clang/test/Misc/warning-wall.c
index c63d4beecff0..9975323f7028 100644
--- a/clang/test/Misc/warning-wall.c
+++ b/clang/test/Misc/warning-wall.c
@@ -9,6 +9,7 @@ CHECK-NEXT:    -Wdelete-non-virtual-dtor
 CHECK-NEXT:      -Wdelete-non-abstract-non-virtual-dtor
 CHECK-NEXT:      -Wdelete-abstract-non-virtual-dtor
 CHECK-NEXT:    -Wformat
+CHECK-NEXT:      -Wformat-insufficient-args
 CHECK-NEXT:      -Wformat-extra-args
 CHECK-NEXT:      -Wformat-zero-length
 CHECK-NEXT:      -Wnonnull

diff  --git a/clang/test/Sema/warn-printf-insufficient-data-args.c b/clang/test/Sema/warn-printf-insufficient-data-args.c
new file mode 100644
index 000000000000..a8de7118e8b1
--- /dev/null
+++ b/clang/test/Sema/warn-printf-insufficient-data-args.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=WARNING-ON %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-format-insufficient-args -verify=WARNING-OFF %s
+
+
+int printf(const char * format, ...);
+
+int main(void) {
+  int patatino = 42;
+  printf("%i %i", patatino); // WARNING-ON-warning {{more '%' conversions than data arguments}}
+  // WARNING-OFF-no-diagnostics
+}


        


More information about the cfe-commits mailing list