Commit 31b72da84a
src/util.cpp
@@ -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);
}
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) {