mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
more info in assertion failures
This commit is contained in:
parent
65b495af58
commit
31b72da84a
@ -18,17 +18,10 @@ void zig_panic(const char *format, ...) {
|
||||
vfprintf(stderr, format, ap);
|
||||
fflush(stderr);
|
||||
va_end(ap);
|
||||
stage2_panic(nullptr, 0);
|
||||
stage2_panic("", 0);
|
||||
abort();
|
||||
}
|
||||
|
||||
void assert(bool ok) {
|
||||
if (!ok) {
|
||||
const char *msg = "Assertion failed. This is a bug in the Zig compiler.";
|
||||
stage2_panic(msg, strlen(msg));
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t int_hash(int i) {
|
||||
return (uint32_t)(i % UINT32_MAX);
|
||||
}
|
||||
|
||||
10
src/util.hpp
10
src/util.hpp
@ -43,15 +43,21 @@ ATTRIBUTE_NORETURN
|
||||
ATTRIBUTE_PRINTF(1, 2)
|
||||
void zig_panic(const char *format, ...);
|
||||
|
||||
static inline void zig_assert(bool ok, const char *file, int line, const char *func) {
|
||||
if (!ok) {
|
||||
zig_panic("Assertion failed at %s:%d in %s. This is a bug in the Zig compiler.", file, line, func);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
#define __func__ __FUNCTION__
|
||||
#endif
|
||||
|
||||
#define zig_unreachable() zig_panic("unreachable: %s:%s:%d", __FILE__, __func__, __LINE__)
|
||||
#define zig_unreachable() zig_panic("Unreachable at %s:%d in %s. This is a bug in the Zig compiler.", __FILE__, __LINE__, __func__)
|
||||
|
||||
// Assertions in stage1 are always on, and they call zig @panic.
|
||||
#undef assert
|
||||
void assert(bool ok);
|
||||
#define assert(ok) zig_assert(ok, __FILE__, __LINE__, __func__)
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
static inline int clzll(unsigned long long mask) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user