xref: /freebsd/contrib/llvm-project/libcxx/include/__verbose_abort (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
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
10#ifndef _LIBCPP___VERBOSE_ABORT
11#define _LIBCPP___VERBOSE_ABORT
12
13#include <__availability>
14#include <__config>
15
16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17#  pragma GCC system_header
18#endif
19
20_LIBCPP_BEGIN_NAMESPACE_STD
21
22// This function should never be called directly from the code -- it should only be called through
23// the _LIBCPP_VERBOSE_ABORT macro.
24_LIBCPP_NORETURN _LIBCPP_AVAILABILITY_VERBOSE_ABORT _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_ATTRIBUTE_FORMAT(__printf__, 1, 2)
25void __libcpp_verbose_abort(const char *__format, ...);
26
27// _LIBCPP_VERBOSE_ABORT(format, args...)
28//
29// This macro is used to abort the program abnormally while providing additional diagnostic information.
30//
31// The first argument is a printf-style format string, and the remaining arguments are values to format
32// into the format-string. This macro can be customized by users to provide fine-grained control over
33// how verbose termination is triggered.
34//
35// If the user does not supply their own version of the _LIBCPP_VERBOSE_ABORT macro, we pick the default
36// behavior based on whether we know the built library we're running against provides support for the
37// verbose termination handler or not. If it does, we call it. If it doesn't, we call __builtin_abort to
38// make sure that the program terminates but without taking any complex dependencies in this header.
39#if !defined(_LIBCPP_VERBOSE_ABORT)
40
41// Support _LIBCPP_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED until LLVM 18, but tell people
42// to move to customizing _LIBCPP_VERBOSE_ABORT instead.
43#  if defined(_LIBCPP_AVAILABILITY_HAS_NO_VERBOSE_ABORT) && defined(_LIBCPP_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED)
44#    undef _LIBCPP_AVAILABILITY_HAS_NO_VERBOSE_ABORT
45#    warning _LIBCPP_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED is deprecated, please customize _LIBCPP_VERBOSE_ABORT instead
46#  endif
47
48#  if defined(_LIBCPP_AVAILABILITY_HAS_NO_VERBOSE_ABORT)
49// The decltype is there to suppress -Wunused warnings in this configuration.
50void __use(const char*, ...);
51#    define _LIBCPP_VERBOSE_ABORT(...) (decltype(::std::__use(__VA_ARGS__))(), __builtin_abort())
52#  else
53#    define _LIBCPP_VERBOSE_ABORT(...) ::std::__libcpp_verbose_abort(__VA_ARGS__)
54#  endif
55
56#endif // !defined(_LIBCPP_VERBOSE_ABORT)
57
58_LIBCPP_END_NAMESPACE_STD
59
60#endif // _LIBCPP___VERBOSE_ABORT
61