5#ifndef BITCOIN_UTIL_CHECK_H
6#define BITCOIN_UTIL_CHECK_H
18#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
25#ifdef ABORT_ON_FAILED_ASSUME
64void assertion_fail(std::string_view file,
int line, std::string_view func, std::string_view assertion);
76 return std::forward<T>(val);
80#error "Cannot compile without assertions!"
84template <
bool IS_ASSERT,
typename T>
85constexpr T&&
inline_assertion_check(
LIFETIMEBOUND T&& val, [[maybe_unused]]
const char* file, [[maybe_unused]]
int line, [[maybe_unused]]
const char* func, [[maybe_unused]]
const char* assertion)
92 return std::forward<T>(val);
98#define STR_INTERNAL_BUG(msg) StrFormatInternalBug((msg), __FILE__, __LINE__, __func__)
111#define CHECK_NONFATAL(condition) \
112 inline_check_non_fatal(condition, __FILE__, __LINE__, __func__, #condition)
115#define Assert(val) inline_assertion_check<true>(val, __FILE__, __LINE__, __func__, #val)
127#define Assume(val) inline_assertion_check<false>(val, __FILE__, __LINE__, __func__, #val)
132#define NONFATAL_UNREACHABLE() \
133 throw NonFatalCheckError( \
134 "Unreachable code reached (non-fatal)", __FILE__, __LINE__, __func__)
138#if defined(__has_feature)
139# if __has_feature(address_sanitizer)
140# include <sanitizer/asan_interface.h>
144#ifndef ASAN_POISON_MEMORY_REGION
145# define ASAN_POISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
146# define ASAN_UNPOISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
T && inline_check_non_fatal(LIFETIMEBOUND T &&val, const char *file, int line, const char *func, const char *assertion)
Helper for CHECK_NONFATAL()
bool g_detail_test_only_CheckFailuresAreExceptionsNotAborts
constexpr T && inline_assertion_check(LIFETIMEBOUND T &&val, const char *file, int line, const char *func, const char *assertion)
Helper for Assert()/Assume()
std::string StrFormatInternalBug(std::string_view msg, std::string_view file, int line, std::string_view func)
void assertion_fail(std::string_view file, int line, std::string_view func, std::string_view assertion)
Internal helper.
std::atomic< bool > g_enable_dynamic_fuzz_determinism
bool EnableFuzzDeterminism()
constexpr bool G_ABORT_ON_FAILED_ASSUME
constexpr bool G_FUZZING_BUILD
NonFatalCheckError(std::string_view msg, std::string_view file, int line, std::string_view func)
#define T(expected, seed, data)
test_only_CheckFailuresAreExceptionsNotAborts()
~test_only_CheckFailuresAreExceptionsNotAborts()