You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.6 KiB

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