public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH RFA(configure)] c++: provide strchrnul on targets without it [PR107781]
@ 2022-11-21 23:31 Jason Merrill
  2022-11-22  8:41 ` Jakub Jelinek
  0 siblings, 1 reply; 4+ messages in thread
From: Jason Merrill @ 2022-11-21 23:31 UTC (permalink / raw)
  To: gcc-patches

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH RFA(configure)] c++: provide strchrnul on targets without it [PR107781]
  2022-11-21 23:31 [PATCH RFA(configure)] c++: provide strchrnul on targets without it [PR107781] Jason Merrill
@ 2022-11-22  8:41 ` Jakub Jelinek
  2022-11-22 11:12   ` Jakub Jelinek
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2022-11-22  8:41 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

On Mon, Nov 21, 2022 at 06:31:47PM -0500, Jason Merrill via Gcc-patches wrote:
> 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.

Normally we'd add such a local definition to libiberty, shouldn't we do it
in this case too?

	Jakub


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH RFA(configure)] c++: provide strchrnul on targets without it [PR107781]
  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
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2022-11-22 11:12 UTC (permalink / raw)
  To: Jason Merrill, gcc-patches

On Tue, Nov 22, 2022 at 09:41:24AM +0100, Jakub Jelinek via Gcc-patches wrote:
> On Mon, Nov 21, 2022 at 06:31:47PM -0500, Jason Merrill via Gcc-patches wrote:
> > 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.
> 
> Normally we'd add such a local definition to libiberty, shouldn't we do it
> in this case too?

Or use strcspn as Jonathan posted in the PR, at least glibc will handle
it as strchrnul (start, reject[0]) - start early in the strcspn
implementation.

	Jakub


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pushed] c++: don't use strchrnul [PR107781]
  2022-11-22 11:12   ` Jakub Jelinek
@ 2022-11-22 14:29     ` Jason Merrill
  0 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2022-11-22 14:29 UTC (permalink / raw)
  To: gcc-patches

As Jonathan suggested.

Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

The contracts implementation was using strchrnul, which is a glibc
extension, so bootstrap broke on non-glibc targets.  Use C89 strcspn
instead.

	PR c++/107781

gcc/cp/ChangeLog:

	* contracts.cc (role_name_equal): Use strcspn instead
	of strchrnul.
---
 gcc/cp/contracts.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/contracts.cc b/gcc/cp/contracts.cc
index f3afcc62ba0..a9097016768 100644
--- a/gcc/cp/contracts.cc
+++ b/gcc/cp/contracts.cc
@@ -210,8 +210,8 @@ lookup_concrete_semantic (const char *name)
 static bool
 role_name_equal (const char *role, const char *name)
 {
-  size_t role_len = strchrnul (role, ':') - role;
-  size_t name_len = strchrnul (name, ':') - name;
+  size_t role_len = strcspn (role, ":");
+  size_t name_len = strcspn (name, ":");
   if (role_len != name_len)
     return false;
   return strncmp (role, name, role_len) == 0;

base-commit: 4eb3a48698b2ca43967a4e7e7cfc0408192e85b2
-- 
2.31.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-22 14:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-21 23:31 [PATCH RFA(configure)] c++: provide strchrnul on targets without it [PR107781] Jason Merrill
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

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