public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Joseph Myers <joseph@codesourcery.com>
To: <libc-alpha@sourceware.org>
Subject: Fix bug-strspn1.c, bug-strpbrk1.c build with GCC mainline [committed]
Date: Wed, 20 Jun 2018 22:19:00 -0000	[thread overview]
Message-ID: <alpine.DEB.2.20.1806202218440.31467@digraph.polyomino.org.uk> (raw)

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.  Committed.

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.

diff --git a/string/bug-strpbrk1.c b/string/bug-strpbrk1.c
index 28238b0..8e909a1 100644
--- a/string/bug-strpbrk1.c
+++ b/string/bug-strpbrk1.c
@@ -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;
 
diff --git a/string/bug-strspn1.c b/string/bug-strspn1.c
index a657baf..e3487ab 100644
--- a/string/bug-strspn1.c
+++ b/string/bug-strspn1.c
@@ -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;
 

-- 
Joseph S. Myers
joseph@codesourcery.com

                 reply	other threads:[~2018-06-20 22:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.20.1806202218440.31467@digraph.polyomino.org.uk \
    --to=joseph@codesourcery.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).