]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c/80619 - bad fix-it hint for GCC %lu directive with int argument: %wu
authorMartin Sebor <msebor@redhat.com>
Tue, 13 Aug 2019 15:55:40 +0000 (15:55 +0000)
committerMartin Sebor <msebor@gcc.gnu.org>
Tue, 13 Aug 2019 15:55:40 +0000 (09:55 -0600)
gcc/c-family/ChangeLog:

PR c/80619
* c-format.c (printf_length_specs): Set FMT_LEN_w for "w".
(asm_fprintf_length_spec): Same.
* c-format.h (format_lengths): Add FMT_LEN_w.

gcc/testsuite/ChangeLog:

PR c/80619
* gcc.dg/format/pr80619.c: New test.

From-SVN: r274385

gcc/c-family/ChangeLog
gcc/c-family/c-format.c
gcc/c-family/c-format.h
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/format/pr80619.c [new file with mode: 0644]

index 507e536e3cab6c5deec45ab8a6ebb52e7dad1ce1..cd7cccb8eb1adf2e41300e5ebde420b918325f7b 100644 (file)
@@ -1,3 +1,10 @@
+2019-08-13  Martin Sebor  <msebor@redhat.com>
+
+       PR c/80619
+       * c-format.c (printf_length_specs): Set FMT_LEN_w for "w".
+       (asm_fprintf_length_spec): Same.
+       * c-format.h (format_lengths): Add FMT_LEN_w.
+
 2019-08-10  Jakub Jelinek  <jakub@redhat.com>
 
        * c-pragma.h (enum pragma_omp_clause): Add
index d134116d598b12fd7a544a508f31779f8e4e9a9b..6b059969e670a25203de193c65d02d2906644e08 100644 (file)
@@ -497,7 +497,7 @@ static const format_length_info printf_length_specs[] =
 static const format_length_info asm_fprintf_length_specs[] =
 {
   { "l", FMT_LEN_l, STD_C89, "ll", FMT_LEN_ll, STD_C89, 0 },
-  { "w", FMT_LEN_none, STD_C89, NO_FMT, 0 },
+  { "w", FMT_LEN_w, STD_C89, NO_FMT, 0 },
   { NO_FMT, NO_FMT, 0 }
 };
 
@@ -505,7 +505,7 @@ static const format_length_info asm_fprintf_length_specs[] =
 static const format_length_info gcc_diag_length_specs[] =
 {
   { "l", FMT_LEN_l, STD_C89, "ll", FMT_LEN_ll, STD_C89, 0 },
-  { "w", FMT_LEN_none, STD_C89, NO_FMT, 0 },
+  { "w", FMT_LEN_w, STD_C89, NO_FMT, 0 },
   { NO_FMT, NO_FMT, 0 }
 };
 
index 972ba46f1095ea13cff9233615d1a186855fd060..6aa68dfe88364c1d421c0dd7d2a108a126b94cd0 100644 (file)
@@ -36,6 +36,7 @@ enum format_lengths
   FMT_LEN_H,
   FMT_LEN_D,
   FMT_LEN_DD,
+  FMT_LEN_w,   /* GCC's HOST_WIDE_INT.  */
   FMT_LEN_MAX
 };
 
index b881498954525b6d01959825f39e06c77630064b..d577f7ed089e16aa204c7e487925b109938cf07d 100644 (file)
@@ -1,3 +1,8 @@
+2019-08-13  Martin Sebor  <msebor@redhat.com>
+
+       PR c/80619
+       * gcc.dg/format/pr80619.c: New test.
+
 2019-08-13  Marek Polacek  <polacek@redhat.com>
 
        PR c++/90473 - wrong code with nullptr in default argument.
diff --git a/gcc/testsuite/gcc.dg/format/pr80619.c b/gcc/testsuite/gcc.dg/format/pr80619.c
new file mode 100644 (file)
index 0000000..c9f0496
--- /dev/null
@@ -0,0 +1,89 @@
+/* PR c/80619 - bad fix-it hint for GCC %lu directive with int argument: %wu
+   { dg-do compile }
+   { dg-options "-Wall -fdiagnostics-show-caret" } */
+
+void T (const char*, ...) __attribute__ ((format (__gcc_diag__, 1, 2)));
+
+void test_suggested_modifier (void)
+{
+  T ("%ld", 0);     // { dg-warning "format '%ld' expects argument of type 'long int', but argument 2 has type 'int'" }
+  /* { dg-begin-multiline-output "" }
+   T ("%ld", 0);
+       ~~^   ~
+         |   |
+         |   int
+         long int
+       %d
+   { dg-end-multiline-output "" } */
+
+  T ("%li", 0);     // { dg-warning "format '%li' expects argument of type 'long int', but argument 2 has type 'int'" }
+  /* { dg-begin-multiline-output "" }
+   T ("%li", 0);
+       ~~^   ~
+         |   |
+         |   int
+         long int
+       %i
+       { dg-end-multiline-output "" } */
+
+  T ("%lu", 0);     // { dg-warning "format '%lu' expects argument of type 'long unsigned int', but argument 2 has type 'int'" }
+  /* { dg-begin-multiline-output "" }
+   T ("%lu", 0);
+       ~~^   ~
+         |   |
+         |   int
+         long unsigned int
+       %u
+       { dg-end-multiline-output "" } */
+
+  T ("%lx", 0);     // { dg-warning "format '%lx' expects argument of type 'long unsigned int', but argument 2 has type 'int'" }
+  /* { dg-begin-multiline-output "" }
+   T ("%lx", 0);
+       ~~^   ~
+         |   |
+         |   int
+         long unsigned int
+       %x
+       { dg-end-multiline-output "" } */
+
+  T ("%lli", 0);    // { dg-warning "format '%lli' expects argument of type 'long long int', but argument 2 has type 'int'" }
+  /* { dg-begin-multiline-output "" }
+   T ("%lli", 0);
+       ~~~^   ~
+          |   |
+          |   int
+          long long int
+       %i
+       { dg-end-multiline-output "" } */
+
+  T ("%llo", 0);    // { dg-warning "format '%llo' expects argument of type 'long long unsigned int', but argument 2 has type 'int'" }
+  /* { dg-begin-multiline-output "" }
+   T ("%llo", 0);
+       ~~~^   ~
+          |   |
+          |   int
+          long long unsigned int
+       %o
+       { dg-end-multiline-output "" } */
+
+  T ("%llu", 0);    // { dg-warning "format '%llu' expects argument of type 'long long unsigned int', but argument 2 has type 'int'" }
+  /* { dg-begin-multiline-output "" }
+   T ("%llu", 0);
+       ~~~^   ~
+          |   |
+          |   int
+          long long unsigned int
+       %u
+       { dg-end-multiline-output "" } */
+
+  T ("%llx", 0);    // { dg-warning "format '%llx' expects argument of type 'long long unsigned int', but argument 2 has type 'int'" }
+  /* { dg-begin-multiline-output "" }
+   T ("%llx", 0);
+       ~~~^   ~
+          |   |
+          |   int
+          long long unsigned int
+       %x
+       { dg-end-multiline-output "" } */
+}
+