Skip to content

Commit

Permalink
Merge branch 'demangle-assert' into 'main'
Browse files Browse the repository at this point in the history
Convert demangling error to assertion

See merge request repositories/verilator-infrastructure-bugpoint!29
  • Loading branch information
sgizler committed Oct 10, 2024
2 parents b98c220 + 092b203 commit 22ff963
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
BasedOnStyle: Chromium
ColumnLimit: 100
IndentWidth: 4
AlignEscapedNewlines: DontAlign
5 changes: 1 addition & 4 deletions source/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 17 additions & 3 deletions source/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 22ff963

Please sign in to comment.