5#ifndef BITCOIN_UTIL_CHECK_H
6#define BITCOIN_UTIL_CHECK_H
12#include <source_location>
19#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
26#ifdef ABORT_ON_FAILED_ASSUME
65void assertion_fail(
const std::source_location& loc, std::string_view assertion);
77 return std::forward<T>(val);
81#error "Cannot compile without assertions!"
85template <
bool IS_ASSERT,
typename T>
93 return std::forward<T>(val);
96#define STR_INTERNAL_BUG(msg) StrFormatInternalBug((msg), std::source_location::current())
109#define CHECK_NONFATAL(condition) \
110 inline_check_non_fatal(condition, std::source_location::current(), #condition)
113#define Assert(val) inline_assertion_check<true>(val, std::source_location::current(), #val)
125#define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val)
130#define NONFATAL_UNREACHABLE() \
131 throw NonFatalCheckError { "Unreachable code reached (non-fatal)", std::source_location::current() }
133#if defined(__has_feature)
134# if __has_feature(address_sanitizer)
135# include <sanitizer/asan_interface.h>
139#ifndef ASAN_POISON_MEMORY_REGION
140# define ASAN_POISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
141# 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()