commit d26a40412197ba61a72368c71e8a8582d686d28c Author: Willy Tarreau Date: Mon Oct 15 11:53:34 2018 +0200 BUILD: compiler: add a new statement "__unreachable()" This statement is used as a hint for the compiler so that it knows that the location where it's placed cannot be reached. It will mostly be used after longjmp() or equivalent statements that deal with error processing and that the compiler doesn't know will not return on certain conditions, so that it doesn't complain about null dereferences on error paths. (cherry picked from commit 8d26f02e693121764bfa0cb48c9a7ab31e17225d) Signed-off-by: Willy Tarreau diff --git a/include/common/compiler.h b/include/common/compiler.h index a13aad5c..6f4f5a67 100644 --- a/include/common/compiler.h +++ b/include/common/compiler.h @@ -82,6 +82,18 @@ */ #define __maybe_unused __attribute__((unused)) +/* This allows gcc to know that some locations are never reached, for example + * after a longjmp() in the Lua code, hence that some errors caught by such + * methods cannot propagate further. This is important with gcc versions 6 and + * above which can more aggressively detect null dereferences. The builtin + * below was introduced in gcc 4.5, and before it we didn't care. + */ +#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) +#define __unreachable() __builtin_unreachable() +#else +#define __unreachable() +#endif + /* * Gcc >= 3 provides the ability for the programme to give hints to the * compiler about what branch of an if is most likely to be taken. This