[RFA(configure)] c++: provide strchrnul on targets without it [PR107781]
Checks
Commit Message
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(-)
base-commit: 5c0d171f67d082c353ddc319859111d3b9126c17
prerequisite-patch-id: 275d90e1bd8b940c1cca2840bc38dc4fafa0797b
Comments
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
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
@@ -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. */
@@ -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
@@ -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"