Add caller location tracking for asserts (ir_assert, src_assert, ir_assert_gen) (#5393)

This commit is contained in:
foobles
2020-05-26 11:55:31 -05:00
committed by GitHub
parent 57b78fff73
commit cb6bc5bdb5
4 changed files with 21 additions and 12 deletions

View File

@@ -9418,15 +9418,16 @@ ZigLLVMDIType *get_llvm_di_type(CodeGen *g, ZigType *type) {
return type->llvm_di_type;
}
void src_assert(bool ok, AstNode *source_node) {
void src_assert_impl(bool ok, AstNode *source_node, char const *file, unsigned int line) {
if (ok) return;
if (source_node == nullptr) {
fprintf(stderr, "when analyzing (unknown source location): ");
fprintf(stderr, "when analyzing (unknown source location) ");
} else {
fprintf(stderr, "when analyzing %s:%u:%u: ",
fprintf(stderr, "when analyzing %s:%u:%u ",
buf_ptr(source_node->owner->data.structure.root_struct->path),
(unsigned)source_node->line + 1, (unsigned)source_node->column + 1);
}
fprintf(stderr, "in compiler source at %s:%u: ", file, line);
const char *msg = "assertion failed. This is a bug in the Zig compiler.";
stage2_panic(msg, strlen(msg));
}