stage1 assertions always on, and have stack traces

This commit is contained in:
Andrew Kelley 2019-04-17 15:58:20 -04:00
parent 4ad7d09ba5
commit ff3cdbc3a0
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
8 changed files with 38 additions and 13 deletions

View File

@ -25,3 +25,7 @@ export fn stage2_zen(ptr: *[*]const u8, len: *usize) void {
ptr.* = &info_zen;
len.* = info_zen.len;
}
export fn stage2_panic(ptr: [*]const u8, len: usize) void {
@panic(ptr[0..len]);
}

View File

@ -10,7 +10,6 @@
#include "list.hpp"
#include <assert.h>
#include <stdint.h>
#include <ctype.h>
#include <stdarg.h>

View File

@ -8,8 +8,6 @@
#ifndef ERROR_HPP
#define ERROR_HPP
#include <assert.h>
enum Error {
ErrorNone,
ErrorNoMem,
@ -56,8 +54,6 @@ enum Error {
const char *err_str(Error err);
static inline void assertNoError(Error err) {
assert(err == ErrorNone);
}
#define assertNoError(err) assert((err) == ErrorNone);
#endif

View File

@ -10,8 +10,6 @@
#include "util.hpp"
#include <assert.h>
template<typename T>
struct ZigList {
void deinit() {

View File

@ -2,9 +2,23 @@
// src-self-hosted/stage1.zig
#include "userland.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void stage2_translate_c(void) {}
void stage2_zen(const char **ptr, size_t *len) {
*ptr = nullptr;
*len = 0;
void stage2_translate_c(void) {
const char *msg = "stage0 called stage2_translate_c";
stage2_panic(msg, strlen(msg));
}
void stage2_zen(const char **ptr, size_t *len) {
const char *msg = "stage0 called stage2_zen";
stage2_panic(msg, strlen(msg));
}
void stage2_panic(const char *ptr, size_t len) {
fwrite(ptr, 1, len, stderr);
fprintf(stderr, "\n");
fflush(stderr);
abort();
}

View File

@ -20,4 +20,6 @@ ZIG_USERLAND_EXTERN_C void stage2_translate_c(void);
ZIG_USERLAND_EXTERN_C void stage2_zen(const char **ptr, size_t *len);
ZIG_USERLAND_EXTERN_C void stage2_panic(const char *ptr, size_t len);
#endif

View File

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

View File

@ -48,6 +48,10 @@ void zig_panic(const char *format, ...);
#define zig_unreachable() zig_panic("unreachable: %s:%s:%d", __FILE__, __func__, __LINE__)
// Assertions in stage1 are always on, and they call zig @panic.
#undef assert
void assert(bool ok);
#if defined(_MSC_VER)
static inline int clzll(unsigned long long mask) {
unsigned long lz;