Skip to contentSkip to conversation

tools include: Add a __fallthrough statement

tip:perf/core tip-bot for Arnaldo Carvalho de Melo 1 participant 1 message Feb 10, 2017

lore
Share & tools
lore
#0 lore raw
Commit-ID:  b5bf1733d6a391c4e90ea8f8468d83023be74a2a
Gitweb:     http://git.kernel.org/tip/b5bf1733d6a391c4e90ea8f8468d83023be74a2a
Author:     Arnaldo Carvalho de Melo <[email protected]>
AuthorDate: Wed, 8 Feb 2017 17:01:46 -0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 8 Feb 2017 17:30:58 -0300

tools include: Add a __fallthrough statement

For cases where implicit fall through case labels are intended, to let us inform that to gcc >= 7:

CC /tmp/build/perf/util/string.o
util/string.c: In function 'perf_atoll':
util/string.c:22:7: error: this statement may fall through [-Werror=implicit-fallthrough=]

      if (*p)
         ^
  util/string.c:24:3: note: here
     case '\0':
     ^~~~

So we introduce:

  #define __fallthrough __attribute__ ((fallthrough))

And use it in such cases.

---
 tools/include/linux/compiler.h | 9 +++++++++
 1 file changed, 9 insertions(+)
tools/include/linux/compiler.h +9 -0
index e33fc1d..d94179f 100644
@@ -126,4 +126,13 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
 #define WRITE_ONCE(x, val) \
 	({ union { typeof(x) __val; char __c[1]; } __u = { .__val = (val) }; __write_once_size(&(x), __u.__c, sizeof(x)); __u.__val; })
 
+
+#ifndef __fallthrough
+# if defined(__GNUC__) && __GNUC__ >= 7
+#  define __fallthrough __attribute__ ((fallthrough))
+# else
+#  define __fallthrough
+# endif
+#endif
+
 #endif /* _TOOLS_LINUX_COMPILER_H */