Skip to content

Commit 7c971c5

Browse files
committed
Strip the full path from __FILE__ in the LDBG macro and keep only the filename
1 parent 56ae79a commit 7c971c5

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

llvm/include/llvm/Support/DebugLog.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@ namespace llvm {
2929
#define DEBUGLOG_WITH_STREAM_AND_TYPE(STREAM, TYPE) \
3030
for (bool _c = (::llvm::DebugFlag && ::llvm::isCurrentDebugType(TYPE)); _c; \
3131
_c = false) \
32-
::llvm::impl::LogWithNewline(TYPE, __FILE__, __LINE__, (STREAM))
32+
::llvm::impl::LogWithNewline( \
33+
TYPE, \
34+
[] { \
35+
/* Force constexpr eval */ \
36+
constexpr const char *filename = \
37+
::llvm::impl::LogWithNewline::getFileName(__FILE__); \
38+
return filename; \
39+
}(), \
40+
__LINE__, (STREAM))
3341

3442
namespace impl {
3543
class LogWithNewline {
@@ -51,6 +59,16 @@ class LogWithNewline {
5159
LogWithNewline(const LogWithNewline &) = delete;
5260
LogWithNewline &operator=(const LogWithNewline &) = delete;
5361
LogWithNewline &operator=(LogWithNewline &&) = delete;
62+
static constexpr const char *getFileName(const char *path) {
63+
// Remove the path prefix from the file name.
64+
const char *filename = path;
65+
for (const char *p = path; *p != '\0'; ++p) {
66+
if (*p == '/' || *p == '\\') {
67+
filename = p + 1;
68+
}
69+
}
70+
return filename;
71+
}
5472

5573
private:
5674
raw_ostream &os;

0 commit comments

Comments
 (0)