Skip to content

Commit 50b2b1b

Browse files
committed
Only print the last component of the filename
In particular, on Windows MSVC, the ASSERT macros use `__FILE__` (with the full pathname) instead of `__FILE_NAME__` (with only the last component).
1 parent fbe7d89 commit 50b2b1b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/Basic/Assertions.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int CONDITIONAL_ASSERT_Global_enable_flag =
3333
#ifdef NDEBUG
3434
0; // Default to `off` in release builds
3535
#else
36-
0; // TODO: Default to `on` in debug builds
36+
1; // Default to `on` in debug builds
3737
#endif
3838

3939
void ASSERT_failure(const char *expr, const char *filename, int line, const char *func) {
@@ -43,8 +43,16 @@ void ASSERT_failure(const char *expr, const char *filename, int line, const char
4343
llvm::errs() << "Assertion help: -Xllvm -assert-help\n";
4444
}
4545

46+
// Find the last component of `filename`
47+
// Needed on Windows MSVC, which lacks __FILE_NAME__
48+
// so we have to use __FILE__ instead:
49+
for (const char *p = filename; *p != '\0'; p++) {
50+
if ((p[0] == '/' || p[0] == '\\')
51+
&& p[1] != '/' && p[1] != '\\' && p[1] != '\0') {
52+
filename = p + 1;
53+
}
54+
}
4655

47-
// Format here matches that used by `assert` on macOS:
4856
llvm::errs()
4957
<< "Assertion failed: "
5058
<< "(" << expr << "), "

0 commit comments

Comments
 (0)