* [PATCH v2] ctype.h: remove duplicate isdigit() helper
@ 2020-10-26 19:20 Arnd Bergmann
2020-10-27 9:47 ` Miguel Ojeda
0 siblings, 1 reply; 4+ messages in thread
From: Arnd Bergmann @ 2020-10-26 19:20 UTC (permalink / raw)
To: arnd
Cc: Luc Van Oostenryck, Nathan Chancellor, Nick Desaulniers,
linux-kernel, clang-built-linux
From: Arnd Bergmann <arnd@arndb.de>
gcc warns a few thousand times about the isdigit() shadow:
include/linux/ctype.h:26:19: warning: declaration of 'isdigit' shadows a built-in function [-Wshadow]
As there is already a compiler builtin, just use that, and make
it clear we do that by defining a macro. Unfortunately, clang
does not have the isdigit() builtin, so this has to be conditional.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
include/linux/compiler.h | 6 ++++++
include/linux/ctype.h | 15 +++++++++++----
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index ac45f6d40d39..b75b49f00ffd 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -136,6 +136,12 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
} while (0)
#endif
+#ifdef __has_builtin
+#define has_builtin(x) __has_builtin(x)
+#else
+#define has_builtin(x) (0)
+#endif
+
/*
* KENTRY - kernel entry point
* This can be used to annotate symbols (functions or data) that are used
diff --git a/include/linux/ctype.h b/include/linux/ctype.h
index 363b004426db..df8233c84b67 100644
--- a/include/linux/ctype.h
+++ b/include/linux/ctype.h
@@ -2,6 +2,8 @@
#ifndef _LINUX_CTYPE_H
#define _LINUX_CTYPE_H
+#include <linux/compiler.h>
+
/*
* NOTE! This ctype does not handle EOF like the standard C
* library is required to.
@@ -23,10 +25,6 @@ extern const unsigned char _ctype[];
#define isalnum(c) ((__ismask(c)&(_U|_L|_D)) != 0)
#define isalpha(c) ((__ismask(c)&(_U|_L)) != 0)
#define iscntrl(c) ((__ismask(c)&(_C)) != 0)
-static inline int isdigit(int c)
-{
- return '0' <= c && c <= '9';
-}
#define isgraph(c) ((__ismask(c)&(_P|_U|_L|_D)) != 0)
#define islower(c) ((__ismask(c)&(_L)) != 0)
#define isprint(c) ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0)
@@ -39,6 +37,15 @@ static inline int isdigit(int c)
#define isascii(c) (((unsigned char)(c))<=0x7f)
#define toascii(c) (((unsigned char)(c))&0x7f)
+#if has_builtin(__builtin_isdigit)
+#define isdigit(c) __builtin_isdigit(c)
+#else
+static inline int isdigit(int c)
+{
+ return '0' <= c && c <= '9';
+}
+#endif
+
static inline unsigned char __tolower(unsigned char c)
{
if (isupper(c))
--
2.27.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ctype.h: remove duplicate isdigit() helper
2020-10-26 19:20 [PATCH v2] ctype.h: remove duplicate isdigit() helper Arnd Bergmann
@ 2020-10-27 9:47 ` Miguel Ojeda
2020-10-27 22:37 ` Arnd Bergmann
0 siblings, 1 reply; 4+ messages in thread
From: Miguel Ojeda @ 2020-10-27 9:47 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Arnd Bergmann, Luc Van Oostenryck, Nathan Chancellor,
Nick Desaulniers, linux-kernel, clang-built-linux
On Tue, Oct 27, 2020 at 12:57 AM Arnd Bergmann <arnd@kernel.org> wrote:
>
> +#ifdef __has_builtin
> +#define has_builtin(x) __has_builtin(x)
> +#else
> +#define has_builtin(x) (0)
> +#endif
Could this be
#ifndef __has_builtin
# define __has_builtin(x) 0
#endif
? i.e. mimicking what we do for `__has_attribute`.
It would also be a nice idea to put a reminder comment like:
/*
* __has_builtin is supported on gcc >= 10, clang >= 3 and icc >= 21.
* In the meantime, to support gcc < 10, we implement __has_builtin
* by hand.
*/
Cheers,
Miguel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ctype.h: remove duplicate isdigit() helper
2020-10-27 9:47 ` Miguel Ojeda
@ 2020-10-27 22:37 ` Arnd Bergmann
2020-10-27 23:00 ` Miguel Ojeda
0 siblings, 1 reply; 4+ messages in thread
From: Arnd Bergmann @ 2020-10-27 22:37 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Luc Van Oostenryck, Nathan Chancellor, Nick Desaulniers,
linux-kernel, clang-built-linux
On Tue, Oct 27, 2020 at 10:47 AM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> On Tue, Oct 27, 2020 at 12:57 AM Arnd Bergmann <arnd@kernel.org> wrote:
> >
> > +#ifdef __has_builtin
> > +#define has_builtin(x) __has_builtin(x)
> > +#else
> > +#define has_builtin(x) (0)
> > +#endif
>
> Could this be
>
> #ifndef __has_builtin
> # define __has_builtin(x) 0
> #endif
>
> ? i.e. mimicking what we do for `__has_attribute`.
Ah, I didn't know about that
> It would also be a nice idea to put a reminder comment like:
>
> /*
> * __has_builtin is supported on gcc >= 10, clang >= 3 and icc >= 21.
> * In the meantime, to support gcc < 10, we implement __has_builtin
> * by hand.
> */
Sounds good, I'll take that. Are the clang and icc version numbers
the actual ones we should list here, or is this just an example?
Arnd
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ctype.h: remove duplicate isdigit() helper
2020-10-27 22:37 ` Arnd Bergmann
@ 2020-10-27 23:00 ` Miguel Ojeda
0 siblings, 0 replies; 4+ messages in thread
From: Miguel Ojeda @ 2020-10-27 23:00 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Luc Van Oostenryck, Nathan Chancellor, Nick Desaulniers,
linux-kernel, clang-built-linux
On Tue, Oct 27, 2020 at 11:37 PM Arnd Bergmann <arnd@kernel.org> wrote:
>
> Sounds good, I'll take that. Are the clang and icc version numbers
> the actual ones we should list here, or is this just an example?
Actual ones -- well, the best approximation I could get from the
available versions in Compiler Explorer :-)
Cheers,
Miguel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-10-27 23:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-26 19:20 [PATCH v2] ctype.h: remove duplicate isdigit() helper Arnd Bergmann
2020-10-27 9:47 ` Miguel Ojeda
2020-10-27 22:37 ` Arnd Bergmann
2020-10-27 23:00 ` Miguel Ojeda
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 NNTP newsgroup(s).