[patch] compiler, clang: move inline definition to compiler-gcc.h

From: David Rientjes
Date: Wed Jun 07 2017 - 01:56:57 EST


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@xxxxxxxxxxxx>
Signed-off-by: David Rientjes <rientjes@xxxxxxxxxx>
---
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))