linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] asm-generic: fix ffs -Wshadow warning
@ 2020-10-26 15:59 Arnd Bergmann
  2020-10-26 16:44 ` David Laight
  0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2020-10-26 15:59 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: linux-arch, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

gcc -Wshadow warns about the ffs() definition that has the
same name as the global ffs() built-in:

include/asm-generic/bitops/builtin-ffs.h:13:28: warning: declaration of 'ffs' shadows a built-in function [-Wshadow]

This is annoying because 'make W=2' warns every time this
header gets included.

Change it to use a #define instead, making callers directly
reference the builtin.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 include/asm-generic/bitops/builtin-ffs.h | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/include/asm-generic/bitops/builtin-ffs.h b/include/asm-generic/bitops/builtin-ffs.h
index 458c85ebcd15..1dacfdb4247e 100644
--- a/include/asm-generic/bitops/builtin-ffs.h
+++ b/include/asm-generic/bitops/builtin-ffs.h
@@ -10,9 +10,6 @@
  * the libc and compiler builtin ffs routines, therefore
  * differs in spirit from the above ffz (man ffs).
  */
-static __always_inline int ffs(int x)
-{
-	return __builtin_ffs(x);
-}
+#define ffs(x) __builtin_ffs(x)
 
 #endif
-- 
2.27.0


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

* RE: [PATCH] asm-generic: fix ffs -Wshadow warning
  2020-10-26 15:59 [PATCH] asm-generic: fix ffs -Wshadow warning Arnd Bergmann
@ 2020-10-26 16:44 ` David Laight
  2020-10-26 18:57   ` Arnd Bergmann
  0 siblings, 1 reply; 3+ messages in thread
From: David Laight @ 2020-10-26 16:44 UTC (permalink / raw)
  To: 'Arnd Bergmann', Arnd Bergmann; +Cc: linux-arch, linux-kernel

From: Arnd Bergmann
> Sent: 26 October 2020 16:00
> 
> From: Arnd Bergmann <arnd@arndb.de>
> 
> gcc -Wshadow warns about the ffs() definition that has the
> same name as the global ffs() built-in:
> 
> include/asm-generic/bitops/builtin-ffs.h:13:28: warning: declaration of 'ffs' shadows a built-in
> function [-Wshadow]
> 
> This is annoying because 'make W=2' warns every time this
> header gets included.
> 
> Change it to use a #define instead, making callers directly
> reference the builtin.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  include/asm-generic/bitops/builtin-ffs.h | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/include/asm-generic/bitops/builtin-ffs.h b/include/asm-generic/bitops/builtin-ffs.h
> index 458c85ebcd15..1dacfdb4247e 100644
> --- a/include/asm-generic/bitops/builtin-ffs.h
> +++ b/include/asm-generic/bitops/builtin-ffs.h
> @@ -10,9 +10,6 @@
>   * the libc and compiler builtin ffs routines, therefore
>   * differs in spirit from the above ffz (man ffs).
>   */
> -static __always_inline int ffs(int x)
> -{
> -	return __builtin_ffs(x);
> -}
> +#define ffs(x) __builtin_ffs(x)
> 
>  #endif
> --
> 2.27.0

An alternative would be to add #define ffs(x) our_inline_ffs(x)
before the inline function definition.

I though the idea of the __builtin_ prefix was that you could
have a function with the same name :-(

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


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

* Re: [PATCH] asm-generic: fix ffs -Wshadow warning
  2020-10-26 16:44 ` David Laight
@ 2020-10-26 18:57   ` Arnd Bergmann
  0 siblings, 0 replies; 3+ messages in thread
From: Arnd Bergmann @ 2020-10-26 18:57 UTC (permalink / raw)
  To: David Laight; +Cc: linux-arch, linux-kernel

On Mon, Oct 26, 2020 at 5:44 PM David Laight <David.Laight@aculab.com> wrote:
>
> An alternative would be to add #define ffs(x) our_inline_ffs(x)
> before the inline function definition.

Yes, that would also work.

> I though the idea of the __builtin_ prefix was that you could
> have a function with the same name :-(

It does multiple things, but one of the things it does is that
the ffs() falls back to the libc-provided ffs() function. You can
define a global ffs() like the libc implementation does, but
defining your own means that it will be used in place of
the official one, which is what the warning is for.

       Arnd

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

end of thread, other threads:[~2020-10-26 18:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-26 15:59 [PATCH] asm-generic: fix ffs -Wshadow warning Arnd Bergmann
2020-10-26 16:44 ` David Laight
2020-10-26 18:57   ` Arnd Bergmann

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