aboutsummaryrefslogtreecommitdiff
path: root/src/util.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-04-17 15:58:20 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-04-17 15:58:20 -0400
commitff3cdbc3a078de1d54c13737264ed62f77ff1f50 (patch)
treeb2ff8f1a46a40a39268153b6f0971e6ee5403817 /src/util.cpp
parent4ad7d09ba5f6f021cb6b6c2045e26fe252f61a27 (diff)
downloadzig-ff3cdbc3a078de1d54c13737264ed62f77ff1f50.tar.gz
zig-ff3cdbc3a078de1d54c13737264ed62f77ff1f50.zip
stage1 assertions always on, and have stack traces
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/util.cpp b/src/util.cpp
index 192d74e766..9a6a382993 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -10,17 +10,25 @@
#include <stdarg.h>
#include "util.hpp"
+#include "userland.h"
void zig_panic(const char *format, ...) {
va_list ap;
va_start(ap, format);
vfprintf(stderr, format, ap);
- fprintf(stderr, "\n");
fflush(stderr);
va_end(ap);
+ stage2_panic(nullptr, 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);
}