public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH RFA(configure)] c++: provide strchrnul on targets without it [PR107781]
Date: Mon, 21 Nov 2022 18:31:47 -0500	[thread overview]
Message-ID: <20221121233147.523576-1-jason@redhat.com> (raw)

Tested x86_64-pc-linux-gnu, and also manually changing the HAVE_DECL_STRCHRNUL
flag.  OK for trunk?

-- 8< --

The Contracts implementation uses strchrnul, which is a glibc extension, so
bootstrap broke on non-glibc targets.  I considered unconditionally using a
local definition, but I guess we might as well use the libc version if it
exists.

	PR c++/107781

gcc/cp/ChangeLog:

	* contracts.cc (strchrnul): Define if needed.

gcc/ChangeLog:

	* configure.ac: Check for strchrnul.
	* config.in, configure: Regenerate.
---
 gcc/cp/contracts.cc | 12 ++++++++++++
 gcc/config.in       |  7 +++++++
 gcc/configure.ac    |  2 +-
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/contracts.cc b/gcc/cp/contracts.cc
index 26396439361..8b11f26ca27 100644
--- a/gcc/cp/contracts.cc
+++ b/gcc/cp/contracts.cc
@@ -204,6 +204,18 @@ lookup_concrete_semantic (const char *name)
   return CCS_INVALID;
 }
 
+#if !HAVE_DECL_STRCHRNUL
+/* strchrnul is a glibc extension.  */
+
+static const char *
+strchrnul (const char *s, char c)
+{
+  if (auto p = strchr (s, c))
+    return p;
+  return strchr (s, '\0');
+}
+#endif
+
 /* Compare role and name up to either the NUL terminator or the first
    occurrence of colon.  */
 
diff --git a/gcc/config.in b/gcc/config.in
index 38ef792bd67..4a5dfb4151c 100644
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -1126,6 +1126,13 @@
 #endif
 
 
+/* Define to 1 if we found a declaration for 'strchrnul', otherwise define to 0.
+   */
+#ifndef USED_FOR_TARGET
+#undef HAVE_DECL_STRCHRNUL
+#endif
+
+
 /* Define to 1 if we found a declaration for 'strnlen', otherwise define to 0.
    */
 #ifndef USED_FOR_TARGET
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 7c55bff6cb0..1124ecfa218 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -1581,7 +1581,7 @@ CXXFLAGS="$CXXFLAGS -I${srcdir} -I${srcdir}/../include $GMPINC"
 # normal autoconf function for these.  But force definition of
 # HAVE_DECL_BASENAME like gcc_AC_CHECK_DECLS does, to suppress the bizarre
 # basename handling in libiberty.h.
-AC_CHECK_DECLS([basename(const char*), strstr(const char*,const char*)], , ,[
+AC_CHECK_DECLS([basename(const char*), strchrnul(const char*, int), strstr(const char*,const char*)], , ,[
 #undef HAVE_DECL_BASENAME
 #define HAVE_DECL_BASENAME 1
 #include "ansidecl.h"

base-commit: 5c0d171f67d082c353ddc319859111d3b9126c17
prerequisite-patch-id: 275d90e1bd8b940c1cca2840bc38dc4fafa0797b
-- 
2.31.1


             reply	other threads:[~2022-11-21 23:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-21 23:31 Jason Merrill [this message]
2022-11-22  8:41 ` Jakub Jelinek
2022-11-22 11:12   ` Jakub Jelinek
2022-11-22 14:29     ` [pushed] c++: don't use strchrnul [PR107781] Jason Merrill

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=20221121233147.523576-1-jason@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.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).