linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] compiler, clang: move inline definition to compiler-gcc.h
@ 2017-06-07  5:56 David Rientjes
  2017-06-07 16:41 ` Matthias Kaehlcke
  0 siblings, 1 reply; 2+ messages in thread
From: David Rientjes @ 2017-06-07  5:56 UTC (permalink / raw)
  To: Matthias Kaehlcke, Linus Torvalds
  Cc: Arnd Bergmann, Linux Kernel Mailing List, Andrew Morton,
	Greg Kroah-Hartman, Ingo Molnar, Thomas Gleixner,
	Christoph Hellwig, Jens Axboe, Steven Rostedt, Douglas Anderson,
	Guenter Roeck, Mark Brown, David Miller

The motivation of commit abb2ea7dfd82 ("compiler, clang: suppress warning 
for unused static inline functions") is to suppress clang's warnings about 
unused static inline functions.

Clang defines __GNUC__ so it inherits all of compiler-gcc.h as well, so 
the redefinition of `inline' ends up overriding the definition in 
compiler-gcc.h.

Simply annotate all inline functions as __attribute__((unused)).  It's 
necessary to suppress the warning for clang and is implicit with gcc.

Reported-by: Matthias Kaehlcke <mka@chromium.org>
Signed-off-by: David Rientjes <rientjes@google.com>
---
 Matthias, please add your Tested-by if this works for you, thanks!

 include/linux/compiler-clang.h |  7 -------
 include/linux/compiler-gcc.h   | 18 ++++++++++--------
 2 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h
--- a/include/linux/compiler-clang.h
+++ b/include/linux/compiler-clang.h
@@ -15,10 +15,3 @@
  * with any version that can compile the kernel
  */
 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
-
-/*
- * GCC does not warn about unused static inline functions for
- * -Wunused-function.  This turns out to avoid the need for complex #ifdef
- * directives.  Suppress the warning in clang as well.
- */
-#define inline inline __attribute__((unused))
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 0efef9cf014f..1264f0688b10 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -65,19 +65,21 @@
 #endif
 
 /*
- * Force always-inline if the user requests it so via the .config,
- * or if gcc is too old:
+ * Force always_inline if the user requests it via the .config, or if gcc is
+ * version 3 or earlier.  Also disable unused static inline function warnings
+ * to avoid the need for complex #ifdef directives: this is implicit with gcc
+ * but is needed for clang, which also sets __GNUC__.
  */
 #if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) ||		\
     !defined(CONFIG_OPTIMIZE_INLINING) || (__GNUC__ < 4)
-#define inline		inline		__attribute__((always_inline)) notrace
-#define __inline__	__inline__	__attribute__((always_inline)) notrace
-#define __inline	__inline	__attribute__((always_inline)) notrace
+#define inline		inline		__attribute__((always_inline,unused)) notrace
+#define __inline__	__inline__	__attribute__((always_inline,unused)) notrace
+#define __inline	__inline	__attribute__((always_inline,unused)) notrace
 #else
 /* A lot of inline functions can cause havoc with function tracing */
-#define inline		inline		notrace
-#define __inline__	__inline__	notrace
-#define __inline	__inline	notrace
+#define inline		inline		__attribute__((unused)) notrace
+#define __inline__	__inline__	__attribute__((unused)) notrace
+#define __inline	__inline	__attribute__((unused)) notrace
 #endif
 
 #define __always_inline	inline __attribute__((always_inline))

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

* Re: [patch] compiler, clang: move inline definition to compiler-gcc.h
  2017-06-07  5:56 [patch] compiler, clang: move inline definition to compiler-gcc.h David Rientjes
@ 2017-06-07 16:41 ` Matthias Kaehlcke
  0 siblings, 0 replies; 2+ messages in thread
From: Matthias Kaehlcke @ 2017-06-07 16:41 UTC (permalink / raw)
  To: David Rientjes
  Cc: Linus Torvalds, Arnd Bergmann, Linux Kernel Mailing List,
	Andrew Morton, Greg Kroah-Hartman, Ingo Molnar, Thomas Gleixner,
	Christoph Hellwig, Jens Axboe, Steven Rostedt, Douglas Anderson,
	Guenter Roeck, Mark Brown, David Miller

El Tue, Jun 06, 2017 at 10:56:49PM -0700 David Rientjes ha dit:

> The motivation of commit abb2ea7dfd82 ("compiler, clang: suppress warning 
> for unused static inline functions") is to suppress clang's warnings about 
> unused static inline functions.
> 
> Clang defines __GNUC__ so it inherits all of compiler-gcc.h as well, so 
> the redefinition of `inline' ends up overriding the definition in 
> compiler-gcc.h.
> 
> Simply annotate all inline functions as __attribute__((unused)).  It's 
> necessary to suppress the warning for clang and is implicit with gcc.
> 
> Reported-by: Matthias Kaehlcke <mka@chromium.org>
> Signed-off-by: David Rientjes <rientjes@google.com>
> ---

Tested-by: Matthias Kaehlcke <mka@chromium.org>

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

end of thread, other threads:[~2017-06-07 16:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-07  5:56 [patch] compiler, clang: move inline definition to compiler-gcc.h David Rientjes
2017-06-07 16:41 ` Matthias Kaehlcke

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