xref: /freebsd/contrib/llvm-project/libcxx/include/__verbose_abort (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
161cfbce3SDimitry Andric// -*- C++ -*-
261cfbce3SDimitry Andric//===----------------------------------------------------------------------===//
361cfbce3SDimitry Andric//
461cfbce3SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
561cfbce3SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
661cfbce3SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
761cfbce3SDimitry Andric//
861cfbce3SDimitry Andric//===----------------------------------------------------------------------===//
961cfbce3SDimitry Andric
1061cfbce3SDimitry Andric#ifndef _LIBCPP___VERBOSE_ABORT
1161cfbce3SDimitry Andric#define _LIBCPP___VERBOSE_ABORT
1261cfbce3SDimitry Andric
1361cfbce3SDimitry Andric#include <__config>
1461cfbce3SDimitry Andric
1561cfbce3SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1661cfbce3SDimitry Andric#  pragma GCC system_header
1761cfbce3SDimitry Andric#endif
1861cfbce3SDimitry Andric
1961cfbce3SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
2061cfbce3SDimitry Andric
21bdd1243dSDimitry Andric// This function should never be called directly from the code -- it should only be called through
22bdd1243dSDimitry Andric// the _LIBCPP_VERBOSE_ABORT macro.
23*cb14a3feSDimitry Andric_LIBCPP_NORETURN _LIBCPP_AVAILABILITY_VERBOSE_ABORT _LIBCPP_OVERRIDABLE_FUNC_VIS
24*cb14a3feSDimitry Andric_LIBCPP_ATTRIBUTE_FORMAT(__printf__, 1, 2) void __libcpp_verbose_abort(const char* __format, ...);
2561cfbce3SDimitry Andric
26bdd1243dSDimitry Andric// _LIBCPP_VERBOSE_ABORT(format, args...)
27bdd1243dSDimitry Andric//
28bdd1243dSDimitry Andric// This macro is used to abort the program abnormally while providing additional diagnostic information.
29bdd1243dSDimitry Andric//
30bdd1243dSDimitry Andric// The first argument is a printf-style format string, and the remaining arguments are values to format
31bdd1243dSDimitry Andric// into the format-string. This macro can be customized by users to provide fine-grained control over
32bdd1243dSDimitry Andric// how verbose termination is triggered.
33bdd1243dSDimitry Andric//
34bdd1243dSDimitry Andric// If the user does not supply their own version of the _LIBCPP_VERBOSE_ABORT macro, we pick the default
35bdd1243dSDimitry Andric// behavior based on whether we know the built library we're running against provides support for the
36bdd1243dSDimitry Andric// verbose termination handler or not. If it does, we call it. If it doesn't, we call __builtin_abort to
37bdd1243dSDimitry Andric// make sure that the program terminates but without taking any complex dependencies in this header.
38bdd1243dSDimitry Andric#if !defined(_LIBCPP_VERBOSE_ABORT)
3961cfbce3SDimitry Andric
405f757f3fSDimitry Andric#  if !_LIBCPP_AVAILABILITY_HAS_VERBOSE_ABORT
4106c3fb27SDimitry Andric// The decltype is there to suppress -Wunused warnings in this configuration.
4206c3fb27SDimitry Andricvoid __use(const char*, ...);
4306c3fb27SDimitry Andric#    define _LIBCPP_VERBOSE_ABORT(...) (decltype(::std::__use(__VA_ARGS__))(), __builtin_abort())
44bdd1243dSDimitry Andric#  else
45bdd1243dSDimitry Andric#    define _LIBCPP_VERBOSE_ABORT(...) ::std::__libcpp_verbose_abort(__VA_ARGS__)
46bdd1243dSDimitry Andric#  endif
4706c3fb27SDimitry Andric
48bdd1243dSDimitry Andric#endif // !defined(_LIBCPP_VERBOSE_ABORT)
49bdd1243dSDimitry Andric
50bdd1243dSDimitry Andric_LIBCPP_END_NAMESPACE_STD
51bdd1243dSDimitry Andric
5261cfbce3SDimitry Andric#endif // _LIBCPP___VERBOSE_ABORT
53