]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
stdio: Suppress %Z format for clang
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 1 Sep 2022 12:29:23 +0000 (09:29 -0300)
committerH.J. Lu <hjl.tools@gmail.com>
Sun, 22 Dec 2024 09:29:28 +0000 (17:29 +0800)
clang does not handle %Z on print, and just suppressing
-Wformat-invalid-specifier might trigger another warning for extra
arguments (since %Z is ignored).  So suppress -Wformat-extra-args
as well.

For tst-fphex.c a heavy hammer is used since the printf is more
complex and clang throws a more generic warning.
Reviewed-by: Sam James <sam@gentoo.org>
stdio-common/bug1.c
stdio-common/bug5.c
stdio-common/test_rdwr.c
stdio-common/tst-fphex.c
stdio-common/tstgetln.c

index 18e7d4c257dc9d6d3c31903e9459673d4b1dbeb7..f23ee5b6bb95254526d60dbde14f3bb4a45813f5 100644 (file)
@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <libc-diag.h>
 
 int
 main (void)
@@ -13,12 +14,22 @@ main (void)
   stream = open_memstream (&bp, &size);
   fprintf (stream, "hello");
   fflush (stream);
+  /* clang do not handle %Z format.  */
+  DIAG_PUSH_NEEDS_COMMENT_CLANG;
+  DIAG_IGNORE_NEEDS_COMMENT_CLANG (13, "-Wformat-invalid-specifier");
+  DIAG_IGNORE_NEEDS_COMMENT_CLANG (13, "-Wformat-extra-args");
   printf ("buf = %s, size = %Zu\n", bp, size);
+  DIAG_POP_NEEDS_COMMENT_CLANG;
   lose |= size != 5;
   lose |= strncmp (bp, "hello", size);
   fprintf (stream, ", world");
   fclose (stream);
+  /* clang do not handle %Z format.  */
+  DIAG_PUSH_NEEDS_COMMENT_CLANG;
+  DIAG_IGNORE_NEEDS_COMMENT_CLANG (13, "-Wformat-invalid-specifier");
+  DIAG_IGNORE_NEEDS_COMMENT_CLANG (13, "-Wformat-extra-args");
   printf ("buf = %s, size = %Zu\n", bp, size);
+  DIAG_POP_NEEDS_COMMENT_CLANG;
   lose |= size != 12;
   lose |= strncmp (bp, "hello, world", 12);
 
index dfa19aed551d8f08b99ac123bc3c5129ec238483..c46810f94cc8fa0a39de029348837f4a9b2d1486 100644 (file)
@@ -6,6 +6,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <libc-diag.h>
 
 #include <support/support.h>
 
@@ -30,7 +31,12 @@ main (void)
       return 1;
     }
   for (i = 0; i < 1000; ++i)
+    /* clang do not handle %Z format.  */
+    DIAG_PUSH_NEEDS_COMMENT_CLANG;
+    DIAG_IGNORE_NEEDS_COMMENT_CLANG (13, "-Wformat-invalid-specifier");
+    DIAG_IGNORE_NEEDS_COMMENT_CLANG (13, "-Wformat-extra-args");
     fprintf (in, "%Zu\n", i);
+    DIAG_POP_NEEDS_COMMENT_CLANG;
 
   out = fopen (outname, "w");
   if (out == NULL)
index 67fbe4e1de1af7996e01693f037501351b44e1e7..8e501ba20f9e9d556d6b93807b6582cabf4f56cb 100644 (file)
@@ -19,6 +19,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <libc-diag.h>
 
 #include <support/xstdio.h>
 
@@ -54,6 +55,11 @@ main (int argc, char **argv)
   rewind (f);
   (void) fputs (buf, f);
   rewind (f);
+
+  /* clang do not handle %Z format.  */
+  DIAG_PUSH_NEEDS_COMMENT_CLANG;
+  DIAG_IGNORE_NEEDS_COMMENT_CLANG (13, "-Wformat-invalid-specifier");
+  DIAG_IGNORE_NEEDS_COMMENT_CLANG (13, "-Wformat-extra-args");
   {
     size_t i;
     for (i = 0; i < replace_from; ++i)
@@ -101,6 +107,7 @@ main (int argc, char **argv)
        lose = 1;
       }
   }
+  DIAG_POP_NEEDS_COMMENT_CLANG;
 
   if (!lose)
     {
index efba48253731b81d8b9c549915205d5846e8c0d0..7c0e4bd6fcdff5ac4ec03158da8e41a5b00f7bc8 100644 (file)
@@ -3,6 +3,7 @@
 #include <array_length.h>
 #include <stdio.h>
 #include <string.h>
+#include <libc-diag.h>
 
 #ifndef WIDE
 # define STR_LEN strlen
@@ -56,10 +57,14 @@ do_test (void)
       int n = SPRINT (buf, array_length (buf), t->fmt, t->value);
       if (n != STR_LEN (t->expect) || STR_CMP (buf, t->expect) != 0)
        {
+         /* clang do not handle %Z format.  */
+         DIAG_PUSH_NEEDS_COMMENT_CLANG;
+         DIAG_IGNORE_NEEDS_COMMENT_CLANG (13, "-Wformat");
          PRINT (L_("" S "\tExpected \"" S "\" (%Zu)\n\tGot      \""
                    S "\" (%d, %Zu)\n"),
                 t->fmt, t->expect, STR_LEN (t->expect),
                 buf, n, STR_LEN (buf));
+         DIAG_POP_NEEDS_COMMENT_CLANG;
          result = 1;
        }
     }
index b2e82632839f55b49cb230aae2fd8c7600b3b3f8..c0a64d22c7fa8a051f0030086e138d9afc421b20 100644 (file)
@@ -16,6 +16,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <stdio.h>
+#include <libc-diag.h>
 
 int
 main (int argc, char *argv[])
@@ -26,7 +27,12 @@ main (int argc, char *argv[])
 
   while ((len = getline (&buf, &size, stdin)) != -1)
     {
+      /* clang do not handle %Z format.  */
+      DIAG_PUSH_NEEDS_COMMENT_CLANG;
+      DIAG_IGNORE_NEEDS_COMMENT_CLANG (13, "-Wformat-invalid-specifier");
+      DIAG_IGNORE_NEEDS_COMMENT_CLANG (13, "-Wformat-extra-args");
       printf ("bufsize %Zu; read %Zd: ", size, len);
+      DIAG_POP_NEEDS_COMMENT_CLANG;
       if (fwrite (buf, len, 1, stdout) != 1)
        {
          perror ("fwrite");