From 092b203466011fe35d3fb00ba6943d10b413ff1b Mon Sep 17 00:00:00 2001 From: Szymon Gizler Date: Thu, 10 Oct 2024 14:58:52 +0200 Subject: [PATCH] Add custom assertion routine --- source/Utils.cpp | 2 +- source/Utils.hpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/source/Utils.cpp b/source/Utils.cpp index 695e87f..3762406 100644 --- a/source/Utils.cpp +++ b/source/Utils.cpp @@ -14,7 +14,7 @@ std::string tryDemangle(const char* mangled) { int rc; char* out = abi::__cxa_demangle(mangled, NULL, NULL, &rc); - assert(rc == 0 && "demangling failed"); + ASSERT(rc == 0, "demangling failed"); std::string outStr = out; free(out); return outStr; diff --git a/source/Utils.hpp b/source/Utils.hpp index 24a9d7b..e4accd5 100644 --- a/source/Utils.hpp +++ b/source/Utils.hpp @@ -89,3 +89,17 @@ std::string prefixLines(const std::string& str, const std::string& linePrefix); fprintf(stderr, "sv-bugpoint: "); \ fprintf(stderr, __VA_ARGS__); \ } while (0) + +#define PRINTF_INTERNAL_ERR(...) \ + do { \ + PRINTF_ERR("Internal error: %s:%d: ", __FILE__, __LINE__); \ + fprintf(stderr, __VA_ARGS__); \ + } while (0) + +#define ASSERT(cond, msg) \ + do { \ + if (!(cond)) { \ + PRINTF_INTERNAL_ERR("Assertion `%s` failed: %s\n", #cond, msg); \ + exit(1); \ + } \ + } while (0)