Remove ASSUME macro

It's dangerous and sometimes bluntly misused feature.
Its optimization potential is near-zero.
This commit is contained in:
Nekotekina 2020-12-10 13:37:26 +03:00
parent 61b882b2a6
commit b382d3b3e9
23 changed files with 40 additions and 68 deletions

View file

@ -372,8 +372,6 @@ public:
// Try to abort by assigning thread_state::aborting (UB if assigning different state)
named_thread& operator=(thread_state s)
{
ASSUME(s == thread_state::aborting);
if (s == thread_state::aborting && thread::m_sync.fetch_op([](u64& v){ return !(v & 3) && (v |= 1); }).second)
{
if (s == thread_state::aborting)

View file

@ -372,7 +372,6 @@ namespace utils
template <typename D = std::remove_reference_t<T>>
auto get() const noexcept
{
ASSUME(m_block->m_type != 0);
return m_block->get_ptr<T>();
}

View file

@ -29,28 +29,13 @@
#endif
#ifdef _MSC_VER
#define ASSUME(...) ((__VA_ARGS__) ? void() : __assume(0)) // MSVC __assume ignores side-effects
#define SAFE_BUFFERS __declspec(safebuffers)
#define NEVER_INLINE __declspec(noinline)
#define FORCE_INLINE __forceinline
#else // not _MSC_VER
#ifdef __clang__
#if defined(__has_builtin) && __has_builtin(__builtin_assume)
#define ASSUME(...) ((__VA_ARGS__) ? void() : __builtin_assume(0)) // __builtin_assume (supported by modern clang) ignores side-effects
#endif
#endif
#ifndef ASSUME // gcc and old clang
#define ASSUME(...) ((__VA_ARGS__) ? void() : __builtin_unreachable()) // note: the compiler will generate code to evaluate "cond" if the expression is opaque
#endif
#define SAFE_BUFFERS __attribute__((no_stack_protector))
#define NEVER_INLINE __attribute__((noinline)) inline
#define FORCE_INLINE __attribute__((always_inline)) inline
#endif // _MSC_VER
#define CHECK_SIZE(type, size) static_assert(sizeof(type) == size, "Invalid " #type " type size")