xref: /llvm-project/libcxx/include/__verbose_abort (revision d269ec321dfdfcd817544da0a94dc42c109694a2)
1507125afSLouis Dionne// -*- C++ -*-
2507125afSLouis Dionne//===----------------------------------------------------------------------===//
3507125afSLouis Dionne//
4507125afSLouis Dionne// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5507125afSLouis Dionne// See https://llvm.org/LICENSE.txt for license information.
6507125afSLouis Dionne// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7507125afSLouis Dionne//
8507125afSLouis Dionne//===----------------------------------------------------------------------===//
9507125afSLouis Dionne
10507125afSLouis Dionne#ifndef _LIBCPP___VERBOSE_ABORT
11507125afSLouis Dionne#define _LIBCPP___VERBOSE_ABORT
12507125afSLouis Dionne
13507125afSLouis Dionne#include <__config>
14507125afSLouis Dionne
15507125afSLouis Dionne#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16507125afSLouis Dionne#  pragma GCC system_header
17507125afSLouis Dionne#endif
18507125afSLouis Dionne
19507125afSLouis Dionne_LIBCPP_BEGIN_NAMESPACE_STD
20507125afSLouis Dionne
21*d269ec32SLouis Dionne#if defined(_LIBCPP_VERBOSE_ABORT_NOT_NOEXCEPT)
22*d269ec32SLouis Dionne#  define _LIBCPP_VERBOSE_ABORT_NOEXCEPT
23*d269ec32SLouis Dionne#else
24*d269ec32SLouis Dionne#  define _LIBCPP_VERBOSE_ABORT_NOEXCEPT _NOEXCEPT
25*d269ec32SLouis Dionne#endif
26*d269ec32SLouis Dionne
2717c05a44SLouis Dionne// This function should never be called directly from the code -- it should only be called through
2817c05a44SLouis Dionne// the _LIBCPP_VERBOSE_ABORT macro.
29*d269ec32SLouis Dionne[[__noreturn__]] _LIBCPP_AVAILABILITY_VERBOSE_ABORT _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_ATTRIBUTE_FORMAT(
30*d269ec32SLouis Dionne    __printf__, 1, 2) void __libcpp_verbose_abort(const char* __format, ...) _LIBCPP_VERBOSE_ABORT_NOEXCEPT;
31507125afSLouis Dionne
3217c05a44SLouis Dionne// _LIBCPP_VERBOSE_ABORT(format, args...)
3317c05a44SLouis Dionne//
3417c05a44SLouis Dionne// This macro is used to abort the program abnormally while providing additional diagnostic information.
3517c05a44SLouis Dionne//
3617c05a44SLouis Dionne// The first argument is a printf-style format string, and the remaining arguments are values to format
3717c05a44SLouis Dionne// into the format-string. This macro can be customized by users to provide fine-grained control over
3817c05a44SLouis Dionne// how verbose termination is triggered.
3917c05a44SLouis Dionne//
4017c05a44SLouis Dionne// If the user does not supply their own version of the _LIBCPP_VERBOSE_ABORT macro, we pick the default
4117c05a44SLouis Dionne// behavior based on whether we know the built library we're running against provides support for the
4217c05a44SLouis Dionne// verbose termination handler or not. If it does, we call it. If it doesn't, we call __builtin_abort to
4317c05a44SLouis Dionne// make sure that the program terminates but without taking any complex dependencies in this header.
4417c05a44SLouis Dionne#if !defined(_LIBCPP_VERBOSE_ABORT)
45507125afSLouis Dionne
4612563ea6Sphilnik777#  if !_LIBCPP_AVAILABILITY_HAS_VERBOSE_ABORT
47308bcb3fSNikolas Klauser// The decltype is there to suppress -Wunused warnings in this configuration.
48867c966cSLouis Dionnevoid __use(const char*, ...);
49bec96f6eSLouis Dionne#    define _LIBCPP_VERBOSE_ABORT(...) (decltype(::std::__use(__VA_ARGS__))(), __builtin_abort())
5017c05a44SLouis Dionne#  else
5117c05a44SLouis Dionne#    define _LIBCPP_VERBOSE_ABORT(...) ::std::__libcpp_verbose_abort(__VA_ARGS__)
5217c05a44SLouis Dionne#  endif
53bec96f6eSLouis Dionne
5417c05a44SLouis Dionne#endif // !defined(_LIBCPP_VERBOSE_ABORT)
5517c05a44SLouis Dionne
5617c05a44SLouis Dionne_LIBCPP_END_NAMESPACE_STD
5717c05a44SLouis Dionne
58507125afSLouis Dionne#endif // _LIBCPP___VERBOSE_ABORT
59