[llvm] Strip the full path from __FILE__ in the LDBG macro and keep only the filename (PR #150677)

Jon Roelofs via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 6 07:54:13 PDT 2025


jroelofs wrote:

> Thanks @jroelofs for reverting in the meantime, and sorry for the breakage! It does not seem like an easy issue to root cause.

I thought we were going to have to take some more drastic measures to bisect this, and wrote up a whole proposal for how to re-architect GreenDragon jobs for automatic bisection: https://github.com/llvm/llvm-zorg/pull/533. That said, we ended up finding it without that after seeing it hit multiple buildbots and intersecting their commit lists. This commit stuck out to me, but I didn't realize why until it clicked for @cachemeifyoucan. Anyway, long-winded way of saying: if you have some time to review my bisection PR, that would help for next time ;)

p.s: I had to revert the revert in f9386d3b1e5977a7920465d072761fc5d70968dc. Did it too hastily, and broke more things.

> I could work something out that would only work with gcc and clang, and let MSVC take the slow path.

@cachemeifyoucan @joker-eph how about:

```
diff --git a/llvm/include/llvm/Support/DebugLog.h b/llvm/include/llvm/Support/DebugLog.h
index a3312950da94..c2007a54e613 100644
--- a/llvm/include/llvm/Support/DebugLog.h
+++ b/llvm/include/llvm/Support/DebugLog.h
@@ -71,10 +71,18 @@ namespace llvm {
   DEBUGLOG_WITH_STREAM_TYPE_FILE_AND_LINE(STREAM, LEVEL, TYPE, FILE, __LINE__)
 // When __SHORT_FILE__ is not defined, the File is the full path,
 // otherwise __SHORT_FILE__ is defined in CMake to provide the file name
-// without the path prefix.
+// without the path prefix. In compilers where __FILE_NAME__ is supported (a
+// clang extension), use that instead, since it helps keep the macro definition
+// the same across all TUs, and therefore allows the module cache entries to be
+// shared across all of them, rather than duplicated.
 #if defined(__SHORT_FILE__)
+#if __has_builtin(__builtin_FILE_NAME)
+#define DEBUGLOG_WITH_STREAM_AND_TYPE(STREAM, LEVEL, TYPE)                     \
+  DEBUGLOG_WITH_STREAM_TYPE_AND_FILE(STREAM, LEVEL, TYPE, __FILE_NAME__)
+#else
 #define DEBUGLOG_WITH_STREAM_AND_TYPE(STREAM, LEVEL, TYPE)                     \
   DEBUGLOG_WITH_STREAM_TYPE_AND_FILE(STREAM, LEVEL, TYPE, __SHORT_FILE__)
+#endif
 #else
 #define DEBUGLOG_WITH_STREAM_AND_TYPE(STREAM, LEVEL, TYPE)                     \
   DEBUGLOG_WITH_STREAM_TYPE_AND_FILE(STREAM, LEVEL, TYPE,                      \
```

https://github.com/llvm/llvm-project/pull/150677


More information about the llvm-commits mailing list