Add AssertPos() macro that provides rough source location in error

It can sometimes be useful to know the general place we were in the program
when an assertion hit; when the position is available / applicable, this
macro is now used.

Issue #268.
This commit is contained in:
Matt Pharr
2012-05-25 10:59:45 -07:00
parent d943455e10
commit 64807dfb3b
7 changed files with 380 additions and 353 deletions

View File

@@ -420,18 +420,41 @@ PerformanceWarning(SourcePos p, const char *fmt, ...) {
}
void
FatalError(const char *file, int line, const char *message) {
fprintf(stderr, "%s(%d): FATAL ERROR: %s\n", file, line, message);
static void
lPrintBugText() {
fprintf(stderr, "***\n"
"*** Please file a bug report at https://github.com/ispc/ispc/issues\n"
"*** (Including as much information as you can about how to "
"reproduce this error).\n"
"*** You have apparently encountered a bug in the compiler that we'd "
"like to fix!\n***\n");
}
void
FatalError(const char *file, int line, const char *message) {
fprintf(stderr, "%s(%d): FATAL ERROR: %s\n", file, line, message);
lPrintBugText();
abort();
}
void
DoAssert(const char *file, int line, const char *expr) {
fprintf(stderr, "%s:%u: Assertion failed: \"%s\".\n", file, line, expr);
lPrintBugText();
abort();
}
void
DoAssertPos(SourcePos pos, const char *file, int line, const char *expr) {
Error(pos, "Assertion failed (%s:%u): \"%s\".", file, line, expr);
lPrintBugText();
abort();
}
///////////////////////////////////////////////////////////////////////////
// http://en.wikipedia.org/wiki/Levenshtein_distance