5 #ifndef BITCOIN_UTIL_CHECK_H 6 #define BITCOIN_UTIL_CHECK_H 12 #include <source_location> 15 #include <string_view> 19 #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION 26 #ifdef ABORT_ON_FAILED_ASSUME 65 void assertion_fail(
const std::source_location& loc, std::string_view assertion);
77 return std::forward<T>(val);
81 #error "Cannot compile without assertions!" 85 template <
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)) 144 #endif // BITCOIN_UTIL_CHECK_H constexpr bool G_ABORT_ON_FAILED_ASSUME
test_only_CheckFailuresAreExceptionsNotAborts()
constexpr T && inline_assertion_check(LIFETIMEBOUND T &&val, [[maybe_unused]] const std::source_location &loc, [[maybe_unused]] std::string_view assertion)
Helper for Assert()/Assume()
constexpr bool G_FUZZING_BUILD
std::string StrFormatInternalBug(std::string_view msg, const std::source_location &loc)
T && inline_check_non_fatal(LIFETIMEBOUND T &&val, const std::source_location &loc, std::string_view assertion)
Helper for CHECK_NONFATAL()
bool g_detail_test_only_CheckFailuresAreExceptionsNotAborts
std::atomic< bool > g_enable_dynamic_fuzz_determinism
~test_only_CheckFailuresAreExceptionsNotAborts()
void assertion_fail(const std::source_location &loc, std::string_view assertion)
Internal helper.
bool EnableFuzzDeterminism()
NonFatalCheckError(std::string_view msg, const std::source_location &loc)
#define T(expected, seed, data)