1
1
mirror of https://github.com/rui314/mold.git synced 2024-11-12 23:48:51 +03:00

Always enable assert()

Our assertions are cheap, and the cost of branch instructions that
are never taken is almost free thanks to hardware branch prediction.
So I don't think it's worth to disable it for release builds.
This commit is contained in:
Rui Ueyama 2022-10-22 15:21:07 +08:00
parent 0d7a5a7284
commit 800fcdc5d4

11
mold.h
View File

@ -1,5 +1,10 @@
#pragma once
// cmake disables assert() for non-release builds by passing -DNDEBUG.
// We want to always enable it, so undefine the macro. This needs to
// be done before `#include <cassert>`.
#undef NDEBUG
#include "inttypes.h"
#include <array>
@ -34,11 +39,7 @@
#define XXH_INLINE_ALL 1
#include "third-party/xxhash/xxhash.h"
#ifdef NDEBUG
# define unreachable() __builtin_unreachable()
#else
# define unreachable() assert(0 && "unreachable")
#endif
#define unreachable() assert(0 && "unreachable")
inline uint64_t hash_string(std::string_view str) {
return XXH3_64bits(str.data(), str.size());