From 08337f3435f71fe8b71a9bf59d41e0591227be84 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Wed, 17 Jan 2024 21:19:24 +0000 Subject: [PATCH] Use fatal_trace consistently for internal errors --- src/cgen.c | 2 +- src/jit/jit-irgen.c | 3 ++- src/lower.c | 2 +- src/rt/heap.c | 19 ++++++------------- src/util.c | 7 ++++++- src/vcode.c | 4 ++-- 6 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/cgen.c b/src/cgen.c index 70897a29..54b4becb 100644 --- a/src/cgen.c +++ b/src/cgen.c @@ -106,7 +106,7 @@ static void cgen_add_dependency(ident_t name, unit_registry_t *ur, { vcode_unit_t vu = unit_registry_get(ur, name); if (vu == NULL) - fatal("missing vcode unit %s", istr(name)); + fatal_trace("missing vcode unit %s", istr(name)); unsigned pos = 0; for (; pos < list->count; pos++) { diff --git a/src/jit/jit-irgen.c b/src/jit/jit-irgen.c index 9a555e79..6b228c83 100644 --- a/src/jit/jit-irgen.c +++ b/src/jit/jit-irgen.c @@ -3855,7 +3855,8 @@ static void irgen_block(jit_irgen_t *g, vcode_block_t block) irgen_op_add_trigger(g, i); break; default: - fatal("cannot generate JIT IR for vcode op %s", vcode_op_string(op)); + fatal_trace("cannot generate JIT IR for vcode op %s", + vcode_op_string(op)); } } } diff --git a/src/lower.c b/src/lower.c index 74e9a947..ff76b427 100644 --- a/src/lower.c +++ b/src/lower.c @@ -1641,7 +1641,7 @@ static int32_t lower_toggle_item_for(lower_unit_t *lu, type_t type, inc = +1; break; default: - fatal("Invalid subkind for range: %d", tree_subkind(r)); + fatal_trace("invalid subkind for range: %d", tree_subkind(r)); } while (1) { diff --git a/src/rt/heap.c b/src/rt/heap.c index 5ff3964d..50b80599 100644 --- a/src/rt/heap.c +++ b/src/rt/heap.c @@ -1,5 +1,5 @@ // -// Copyright (C) 2011-2023 Nick Gasson +// Copyright (C) 2011-2024 Nick Gasson // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -19,6 +19,7 @@ #include "rt/heap.h" #include "rt/rt.h" +#include #include #include @@ -67,8 +68,7 @@ static void min_heapify(heap_t *h, size_t i) static inline void heap_decrease_key(heap_t *h, size_t i, uint64_t key) { - if (unlikely(key > KEY(h, i))) - fatal("new key is larger than current key") LCOV_EXCL_LINE; + assert(key <= KEY(h, i)); KEY(h, i) = key; while (i > 1 && KEY(h, PARENT(i)) > KEY(h, i)) { @@ -96,8 +96,7 @@ void *heap_extract_min(heap_t *h) { RT_LOCK(h->lock); - if (unlikely(h->size < 1)) - fatal_trace("heap underflow") LCOV_EXCL_LINE; + assert(h->size >= 1); void *min = USER(h, 1); NODE(h, 1) = NODE(h, h->size); @@ -109,20 +108,14 @@ void *heap_extract_min(heap_t *h) void *heap_min(heap_t *h) { RT_LOCK(h->lock); - - if (unlikely(h->size < 1)) - fatal_trace("heap underflow") LCOV_EXCL_LINE; - + assert(h->size >= 1); return USER(h, 1); } uint64_t heap_min_key(heap_t *h) { RT_LOCK(h->lock); - - if (unlikely(h->size < 1)) - fatal_trace("heap underflow") LCOV_EXCL_LINE; - + assert(h->size >= 1); return KEY(h, 1); } diff --git a/src/util.c b/src/util.c index 3d572574..7c8746f9 100644 --- a/src/util.c +++ b/src/util.c @@ -1,5 +1,5 @@ // -// Copyright (C) 2011-2023 Nick Gasson +// Copyright (C) 2011-2024 Nick Gasson // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -695,6 +695,11 @@ void show_stacktrace(void) "installing the libdw-dev package and reconfiguring$$\n"); #endif +#ifndef DEBUG + color_fprintf(stderr, "\n$!red$Please report this bug at " + PACKAGE_BUGREPORT "$$\n"); +#endif + fflush(stderr); } diff --git a/src/vcode.c b/src/vcode.c index 102d7c21..9e733acc 100644 --- a/src/vcode.c +++ b/src/vcode.c @@ -689,8 +689,8 @@ void vcode_opt(void) case VCODE_OP_ALLOC: if (uses[o->result] == -1) { vcode_dump_with_mark(j, NULL, NULL); - fatal("defintion of r%d does not dominate all uses", - o->result); + fatal_trace("definition of r%d does not dominate all uses", + o->result); } else if (uses[o->result] == 0) { if (false DEBUG_ONLY(|| o->kind != VCODE_OP_CONST)) { -- 2.39.2