diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/assert.h | 5 | ||||
-rw-r--r-- | src/common/common_funcs.h | 12 | ||||
-rw-r--r-- | src/common/hash.h | 35 | ||||
-rw-r--r-- | src/common/logging/backend.cpp | 8 |
4 files changed, 16 insertions, 44 deletions
diff --git a/src/common/assert.h b/src/common/assert.h index 4b0e3f64e..5b67c5c52 100644 --- a/src/common/assert.h +++ b/src/common/assert.h @@ -41,8 +41,9 @@ __declspec(noinline, noreturn) } \ while (0) -#define UNREACHABLE() ASSERT_MSG(false, "Unreachable code!") -#define UNREACHABLE_MSG(...) ASSERT_MSG(false, __VA_ARGS__) +#define UNREACHABLE() assert_noinline_call([] { LOG_CRITICAL(Debug, "Unreachable code!"); }) +#define UNREACHABLE_MSG(...) \ + assert_noinline_call([&] { LOG_CRITICAL(Debug, "Unreachable code!\n" __VA_ARGS__); }) #ifdef _DEBUG #define DEBUG_ASSERT(_a_) ASSERT(_a_) diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index c029dc7b3..052254678 100644 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h @@ -19,13 +19,15 @@ /// Helper macros to insert unused bytes or words to properly align structs. These values will be /// zero-initialized. -#define INSERT_PADDING_BYTES(num_bytes) std::array<u8, num_bytes> CONCAT2(pad, __LINE__){}; -#define INSERT_PADDING_WORDS(num_words) std::array<u32, num_words> CONCAT2(pad, __LINE__){}; +#define INSERT_PADDING_BYTES(num_bytes) \ + std::array<u8, num_bytes> CONCAT2(pad, __LINE__) {} +#define INSERT_PADDING_WORDS(num_words) \ + std::array<u32, num_words> CONCAT2(pad, __LINE__) {} /// These are similar to the INSERT_PADDING_* macros, but are needed for padding unions. This is /// because unions can only be initialized by one member. -#define INSERT_UNION_PADDING_BYTES(num_bytes) std::array<u8, num_bytes> CONCAT2(pad, __LINE__); -#define INSERT_UNION_PADDING_WORDS(num_words) std::array<u32, num_words> CONCAT2(pad, __LINE__); +#define INSERT_UNION_PADDING_BYTES(num_bytes) std::array<u8, num_bytes> CONCAT2(pad, __LINE__) +#define INSERT_UNION_PADDING_WORDS(num_words) std::array<u32, num_words> CONCAT2(pad, __LINE__) #ifndef _MSC_VER @@ -56,7 +58,7 @@ std::string GetLastErrorMsg(); namespace Common { constexpr u32 MakeMagic(char a, char b, char c, char d) { - return a | b << 8 | c << 16 | d << 24; + return u32(a) | u32(b) << 8 | u32(c) << 16 | u32(d) << 24; } } // namespace Common diff --git a/src/common/hash.h b/src/common/hash.h index ebd4125e2..b2538f3ea 100644 --- a/src/common/hash.h +++ b/src/common/hash.h @@ -35,41 +35,6 @@ static inline u64 ComputeStructHash64(const T& data) { return ComputeHash64(&data, sizeof(data)); } -/// A helper template that ensures the padding in a struct is initialized by memsetting to 0. -template <typename T> -struct HashableStruct { - // In addition to being trivially copyable, T must also have a trivial default constructor, - // because any member initialization would be overridden by memset - static_assert(std::is_trivial_v<T>, "Type passed to HashableStruct must be trivial"); - /* - * We use a union because "implicitly-defined copy/move constructor for a union X copies the - * object representation of X." and "implicitly-defined copy assignment operator for a union X - * copies the object representation (3.9) of X." = Bytewise copy instead of memberwise copy. - * This is important because the padding bytes are included in the hash and comparison between - * objects. - */ - union { - T state; - }; - - HashableStruct() { - // Memset structure to zero padding bits, so that they will be deterministic when hashing - std::memset(&state, 0, sizeof(T)); - } - - bool operator==(const HashableStruct<T>& o) const { - return std::memcmp(&state, &o.state, sizeof(T)) == 0; - }; - - bool operator!=(const HashableStruct<T>& o) const { - return !(*this == o); - }; - - std::size_t Hash() const { - return Common::ComputeStructHash64(state); - } -}; - struct PairHash { template <class T1, class T2> std::size_t operator()(const std::pair<T1, T2>& pair) const noexcept { diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 1111cfbad..8f2591d53 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -272,8 +272,10 @@ const char* GetLogClassName(Class log_class) { #undef CLS #undef SUB case Class::Count: - UNREACHABLE(); + break; } + UNREACHABLE(); + return "Invalid"; } const char* GetLevelName(Level log_level) { @@ -288,9 +290,11 @@ const char* GetLevelName(Level log_level) { LVL(Error); LVL(Critical); case Level::Count: - UNREACHABLE(); + break; } #undef LVL + UNREACHABLE(); + return "Invalid"; } void SetGlobalFilter(const Filter& filter) { |