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___LOG_HARDENING_FAILURE
11#define _LIBCPP___LOG_HARDENING_FAILURE
12
13#include <__config>
14
15#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16# pragma GCC system_header
17#endif
18
19// Hardening logging is not available in the C++03 mode; moreover, it is currently only available in the experimental
20// library.
21#if _LIBCPP_HAS_EXPERIMENTAL_HARDENING_OBSERVE_SEMANTIC && !defined(_LIBCPP_CXX03_LANG)
22
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25// This function should never be called directly from the code -- it should only be called through the
26// `_LIBCPP_LOG_HARDENING_FAILURE` macro.
27_LIBCPP_BEGIN_EXPLICIT_ABI_ANNOTATIONS
28[[__gnu__::__cold__]] _LIBCPP_EXPORTED_FROM_ABI void __log_hardening_failure(const char* __message) noexcept;
29_LIBCPP_END_EXPLICIT_ABI_ANNOTATIONS
30
31// _LIBCPP_LOG_HARDENING_FAILURE(message)
32//
33// This macro is used to log an error without terminating the program (as is the case for hardening failures if the
34// `observe` assertion semantic is used).
35
36# if !defined(_LIBCPP_LOG_HARDENING_FAILURE)
37# define _LIBCPP_LOG_HARDENING_FAILURE(__message) ::std::__log_hardening_failure(__message)
38# endif // !defined(_LIBCPP_LOG_HARDENING_FAILURE)
39
40_LIBCPP_END_NAMESPACE_STD
41
42#endif // _LIBCPP_HAS_EXPERIMENTAL_HARDENING_OBSERVE_SEMANTIC && !defined(_LIBCPP_CXX03_LANG)
43
44#endif // _LIBCPP___LOG_HARDENING_FAILURE
45