5#ifndef BITCOIN_UTIL_CHECK_H
6#define BITCOIN_UTIL_CHECK_H
14#include <source_location>
22#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
29#ifdef ABORT_ON_FAILED_ASSUME
68void assertion_fail(
const std::source_location& loc, std::string_view assertion);
80 return std::forward<T>(val);
84#error "Cannot compile without assertions!"
88template <
bool IS_ASSERT,
typename T>
96 return std::forward<T>(val);
99#define STR_INTERNAL_BUG(msg) StrFormatInternalBug((msg), std::source_location::current())
112#define CHECK_NONFATAL(condition) \
113 inline_check_non_fatal(condition, std::source_location::current(), #condition)
116#define Assert(val) inline_assertion_check<true>(val, std::source_location::current(), #val)
128#define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val)
133#define NONFATAL_UNREACHABLE() \
134 throw NonFatalCheckError { "Unreachable code reached (non-fatal)", std::source_location::current() }
136#if defined(__has_feature)
137# if __has_feature(address_sanitizer)
138# include <sanitizer/asan_interface.h>
142#ifndef ASAN_POISON_MEMORY_REGION
143# define ASAN_POISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
144# define ASAN_UNPOISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
bool g_detail_test_only_CheckFailuresAreExceptionsNotAborts
constexpr T && inline_assertion_check(LIFETIMEBOUND T &&val, const std::source_location &loc, std::string_view assertion)
Helper for Assert()/Assume()
T && inline_check_non_fatal(LIFETIMEBOUND T &&val, const std::source_location &loc, std::string_view assertion)
Helper for CHECK_NONFATAL()
std::atomic< bool > g_enable_dynamic_fuzz_determinism
std::string StrFormatInternalBug(std::string_view msg, const std::source_location &loc)
bool EnableFuzzDeterminism()
constexpr bool G_ABORT_ON_FAILED_ASSUME
void assertion_fail(const std::source_location &loc, std::string_view assertion)
Internal helper.
constexpr bool G_FUZZING_BUILD
NonFatalCheckError(std::string_view msg, const std::source_location &loc)
#define T(expected, seed, data)
test_only_CheckFailuresAreExceptionsNotAborts()
~test_only_CheckFailuresAreExceptionsNotAborts()