0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 10:12:39 +01:00

ircd: Add always_assert() inline expression trap.

This commit is contained in:
Jason Volk 2019-12-26 14:38:51 -08:00
parent 37cde44d58
commit 316d668a58

View file

@ -34,8 +34,9 @@
// Our utils // Our utils
namespace ircd namespace ircd
{ {
void print_assertion(const char *const &, const char *const &, const unsigned &, const char *const &) noexcept;
void debugtrap() noexcept; void debugtrap() noexcept;
void always_assert(const bool &) noexcept;
void print_assertion(const char *const &, const char *const &, const unsigned &, const char *const &) noexcept;
} }
/// Override the standard assert behavior, if enabled, to trap into the /// Override the standard assert behavior, if enabled, to trap into the
@ -84,3 +85,13 @@ noexcept
__builtin_trap(); __builtin_trap();
#endif #endif
} }
/// Trap on false expression whether or not NDEBUG.
extern inline void
__attribute__((always_inline, gnu_inline, artificial))
ircd::always_assert(const bool &expr)
noexcept
{
if(__builtin_expect(!expr, 0))
debugtrap();
}