__verbose_abort 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP___VERBOSE_ABORT
  10. #define _LIBCPP___VERBOSE_ABORT
  11. #include <__availability>
  12. #include <__config>
  13. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  14. # pragma GCC system_header
  15. #endif
  16. _LIBCPP_BEGIN_NAMESPACE_STD
  17. // This function should never be called directly from the code -- it should only be called through
  18. // the _LIBCPP_VERBOSE_ABORT macro.
  19. _LIBCPP_NORETURN _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 1, 2)
  20. void __libcpp_verbose_abort(const char *__format, ...);
  21. // _LIBCPP_VERBOSE_ABORT(format, args...)
  22. //
  23. // This macro is used to abort the program abnormally while providing additional diagnostic information.
  24. //
  25. // The first argument is a printf-style format string, and the remaining arguments are values to format
  26. // into the format-string. This macro can be customized by users to provide fine-grained control over
  27. // how verbose termination is triggered.
  28. //
  29. // If the user does not supply their own version of the _LIBCPP_VERBOSE_ABORT macro, we pick the default
  30. // behavior based on whether we know the built library we're running against provides support for the
  31. // verbose termination handler or not. If it does, we call it. If it doesn't, we call __builtin_abort to
  32. // make sure that the program terminates but without taking any complex dependencies in this header.
  33. #if !defined(_LIBCPP_VERBOSE_ABORT)
  34. // Support _LIBCPP_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED until LLVM 18, but tell people
  35. // to move to customizing _LIBCPP_VERBOSE_ABORT instead.
  36. # if defined(_LIBCPP_HAS_NO_VERBOSE_ABORT_IN_LIBRARY) && defined(_LIBCPP_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED)
  37. # undef _LIBCPP_HAS_NO_VERBOSE_ABORT_IN_LIBRARY
  38. # warning _LIBCPP_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED is deprecated, please customize _LIBCPP_VERBOSE_ABORT instead
  39. # endif
  40. # if defined(_LIBCPP_HAS_NO_VERBOSE_ABORT_IN_LIBRARY)
  41. # define _LIBCPP_VERBOSE_ABORT(...) __builtin_abort()
  42. # else
  43. # define _LIBCPP_VERBOSE_ABORT(...) ::std::__libcpp_verbose_abort(__VA_ARGS__)
  44. # endif
  45. #endif // !defined(_LIBCPP_VERBOSE_ABORT)
  46. _LIBCPP_END_NAMESPACE_STD
  47. #endif // _LIBCPP___VERBOSE_ABORT