This adds the UNREACHABLE() macro to <linux/compiler.h>. The latest GCC has __builtin_unreachable(), which makes it generate better code (i.e. omit some unreachable instructions). Signed-off-by: Roland McGrath <roland@xxxxxxxxxx> CC: Jakub Jelinek <jakub@xxxxxxxxxx> --- include/linux/compiler-gcc4.h | 13 +++++++++++++ include/linux/compiler.h | 9 +++++++++ 2 files changed, 22 insertions(+), 0 deletions(-) diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h index 450fa59..320a9ad 100644 --- a/include/linux/compiler-gcc4.h +++ b/include/linux/compiler-gcc4.h @@ -37,3 +37,16 @@ #define __cold __attribute__((__cold__)) #endif + +/* + * __builtin_unreachable is available in GCC 4.5+ and + * also in Fedora/Red Hat GCC 4.4.1-10+. + */ +#if (__GNUC_MINOR__ > 4 \ + || (__GNUC_MINOR__ == 4 \ + && defined __GNUC_RH_RELEASE__ \ + && (__GNUC_PATCHLEVEL__ > 1 \ + || (__GNUC_PATCHLEVEL__ == 1 \ + && __GNUC_RH_RELEASE__ >= 10)))) +#define UNREACHABLE() __builtin_unreachable() +#endif diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 04fb513..e3dc896 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -256,6 +256,15 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect); #define __cold #endif +/* + * Tell the compiler following code is unreachable and should disappear. + * If nothing else, just make it obvious to avoid warnings about missing + * return or whatnot. Some compilers define a way to optimize it better. + */ +#ifndef UNREACHABLE +#define UNREACHABLE() for (;;) +#endif + /* Simple shorthand for a section definition */ #ifndef __section # define __section(S) __attribute__ ((__section__(#S))) -- To unsubscribe from this list: send the line "unsubscribe linux-arch" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html