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

Mehdi Amini via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 25 11:59:58 PDT 2025


================
@@ -51,6 +59,16 @@ class LogWithNewline {
   LogWithNewline(const LogWithNewline &) = delete;
   LogWithNewline &operator=(const LogWithNewline &) = delete;
   LogWithNewline &operator=(LogWithNewline &&) = delete;
+  static constexpr const char *getFileName(const char *path) {
+    // Remove the path prefix from the file name.
+    const char *filename = path;
+    for (const char *p = path; *p != '\0'; ++p) {
----------------
joker-eph wrote:

Right, do you have a better alternative in mind? I would think you need to traverse the string once at least regardless of the solution.

The better way I could think of would be to avoid doing it on each macro usage, using help from CMake.

For example, if there is a `__LLVM_SHORT_FILENAME__` macro set then use it, otherwise do the linear scan.

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


More information about the llvm-commits mailing list