Skip to content

Commit

Permalink
Add LIBHAT_UNREACHABLE macro
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroMemes committed Aug 1, 2024
1 parent 3ee98fd commit f593858
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
17 changes: 17 additions & 0 deletions include/libhat/Defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,20 @@
#else
#define LIBHAT_UNLIKELY
#endif

#if __cpp_lib_unreachable >= 202202L
#include <utility>
#define LIBHAT_UNREACHABLE() std::unreachable()
#elif defined(_MSC_VER)
#define LIBHAT_UNREACHABLE() __assume(false)
#elif defined(__GNUC__)
#define LIBHAT_UNREACHABLE() __builtin_unreachable()
#else
#include <cstdlib>
namespace hat::detail {
[[noreturn]] inline void unreachable_impl() {
std::abort();
}
}
#define LIBHAT_UNREACHABLE() hat::detail::unreachable_impl()
#endif
2 changes: 1 addition & 1 deletion include/libhat/Scanner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ namespace hat {
case scan_alignment::X1: return &find_pattern_single<scan_alignment::X1>;
case scan_alignment::X16: return &find_pattern_single<scan_alignment::X16>;
}
std::unreachable();
LIBHAT_UNREACHABLE();
}

[[nodiscard]] constexpr auto truncate(const signature_view signature) noexcept {
Expand Down
2 changes: 1 addition & 1 deletion src/arch/x86/AVX2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ namespace hat::detail {
return &find_pattern_avx2<scan_alignment::X16, false, false>;
}
}
std::unreachable();
LIBHAT_UNREACHABLE();
}
}
#endif
2 changes: 1 addition & 1 deletion src/arch/x86/AVX512.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ namespace hat::detail {
return &find_pattern_avx512<scan_alignment::X16, false, false>;
}
}
std::unreachable();
LIBHAT_UNREACHABLE();
}
}
#endif
2 changes: 1 addition & 1 deletion src/arch/x86/SSE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ namespace hat::detail {
return &find_pattern_sse<scan_alignment::X16, false, false>;
}
}
std::unreachable();
LIBHAT_UNREACHABLE();
}
}
#endif

0 comments on commit f593858

Please sign in to comment.