diff --git a/.clang-format b/.clang-format index 26cb1dd..e707e6c 100644 --- a/.clang-format +++ b/.clang-format @@ -2,3 +2,4 @@ BasedOnStyle: Chromium ColumnLimit: 100 IndentWidth: 4 +AlignEscapedNewlines: DontAlign diff --git a/source/Utils.cpp b/source/Utils.cpp index 242840a..3762406 100644 --- a/source/Utils.cpp +++ b/source/Utils.cpp @@ -14,10 +14,7 @@ std::string tryDemangle(const char* mangled) { int rc; char* out = abi::__cxa_demangle(mangled, NULL, NULL, &rc); - if (rc != 0) { - PRINTF_ERR("demangling error\n"); - exit(1); - } + ASSERT(rc == 0, "demangling failed"); std::string outStr = out; free(out); return outStr; diff --git a/source/Utils.hpp b/source/Utils.hpp index 55ee94d..e4accd5 100644 --- a/source/Utils.hpp +++ b/source/Utils.hpp @@ -84,8 +84,22 @@ std::string prefixLines(const std::string& str, const std::string& linePrefix); // NOTE: doing it as variadic func rather than macro would prevent // compiler from issuing warnings about incorrect format string -#define PRINTF_ERR(...) \ - do { \ +#define PRINTF_ERR(...) \ + do { \ fprintf(stderr, "sv-bugpoint: "); \ - fprintf(stderr, __VA_ARGS__); \ + 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)