]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix bug-strspn1.c, bug-strpbrk1.c build with GCC mainline.
authorJoseph Myers <joseph@codesourcery.com>
Wed, 20 Jun 2018 22:18:22 +0000 (22:18 +0000)
committerJoseph Myers <joseph@codesourcery.com>
Wed, 20 Jun 2018 22:18:22 +0000 (22:18 +0000)
Building the testsuite with GCC mainline fails with:

bug-strspn1.c: In function 'main':
bug-strspn1.c:14:3: error: right-hand operand of comma expression has no effect [-Werror=unused-value]
   strspn (b++, "");
   ^~~~~~~~~~~~~~~~

and a similar error for bug-strpbrk1.c.  I'm not sure what GCC change
introduced this, and the wording of the message is a bit off (in the
source it's not a comma expression, that must reflect GCC's IR).  But
the warning is correct (strspn is a pure function, the call is
useless, and if there wasn't an argument with a side effect much older
GCC would have warned); the point of the test is to verify that the
side effect in an argument still occurs for this useless call that can
otherwise be optimized to an (unused) constant (testing for a bug
there once was in an old strspn macro).  This patch duly arranges for
the warning to be disabled for this code.

Tested with build-many-glibcs.py for aarch64-linux-gnu.

* string/bug-strpbrk1.c: Include <libc-diag.h>.
(main): Disable -Wunused-value around call to strpbrk.
* string/bug-strspn1.c: Include <libc-diag.h>.
(main): Disable -Wunused-value around call to strspn.

ChangeLog
string/bug-strpbrk1.c
string/bug-strspn1.c

index 479e90fbf3b45fd41b7a160c93aaf6d714c2f6cb..ce0266a35edf355758ffa599f4e4afa313520d9a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2018-06-20  Joseph Myers  <joseph@codesourcery.com>
+
+       * string/bug-strpbrk1.c: Include <libc-diag.h>.
+       (main): Disable -Wunused-value around call to strpbrk.
+       * string/bug-strspn1.c: Include <libc-diag.h>.
+       (main): Disable -Wunused-value around call to strspn.
+
 2018-06-20  Tulio Magno Quites Machado Filho  <tuliom@linux.ibm.com>
            Gabriel F. T. Gomes  <gabriel@inconstante.eti.br>
 
index 28238b0f50a588ed5719f0fd802a87466eed3871..8e909a1e21288142b93c7f19750dbd05b97db28a 100644 (file)
@@ -4,6 +4,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <libc-diag.h>
 
 int
 main (void)
@@ -11,7 +12,14 @@ main (void)
   const char *a = "abc";
   const char *b = a;
 
+  DIAG_PUSH_NEEDS_COMMENT;
+  /* GCC 9 correctly warns that this call to strpbrk is useless.  That
+     is deliberate; this test is verifying that a side effect in an
+     argument still occurs when the call itself is useless and could
+     be optimized to return a constant.  */
+  DIAG_IGNORE_NEEDS_COMMENT (9, "-Wunused-value");
   strpbrk (b++, "");
+  DIAG_POP_NEEDS_COMMENT;
   if (b != a + 1)
     return 1;
 
index a657bafc43f4b07c3c40660dc715dfefd3f10e69..e3487ab8f928dc11b26049e53c88b0596c8fae38 100644 (file)
@@ -4,6 +4,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <libc-diag.h>
 
 int
 main (void)
@@ -11,7 +12,14 @@ main (void)
   const char *a = "abc";
   const char *b = a;
 
+  DIAG_PUSH_NEEDS_COMMENT;
+  /* GCC 9 correctly warns that this call to strspn is useless.  That
+     is deliberate; this test is verifying that a side effect in an
+     argument still occurs when the call itself is useless and could
+     be optimized to return a constant.  */
+  DIAG_IGNORE_NEEDS_COMMENT (9, "-Wunused-value");
   strspn (b++, "");
+  DIAG_POP_NEEDS_COMMENT;
   if (b != a + 1)
     return 1;