more info in assertion failures

This commit is contained in:
Andrew Kelley 2019-09-22 16:40:48 -04:00
parent 65b495af58
commit 31b72da84a
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
2 changed files with 9 additions and 10 deletions

View File

@ -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);
}

View File

@ -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) {