[llvm] b018151 - [Utils] Compare true file locations instead of string paths (#158160)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 11 15:49:34 PDT 2025


Author: Henrik G. Olsson
Date: 2025-09-11T22:49:30Z
New Revision: b0181514b4d2a5f61ae5b405ee32643e6b8ff71b

URL: https://github.com/llvm/llvm-project/commit/b0181514b4d2a5f61ae5b405ee32643e6b8ff71b
DIFF: https://github.com/llvm/llvm-project/commit/b0181514b4d2a5f61ae5b405ee32643e6b8ff71b.diff

LOG: [Utils] Compare true file locations instead of string paths (#158160)

Previously we compared paths by string manipulation, however Windows
paths can use both '\' and '/' as path separators, which made this
fragile. This uses the pathlib.Path.samefile API instead.

Added: 
    

Modified: 
    llvm/utils/lit/lit/DiffUpdater.py

Removed: 
    


################################################################################
diff  --git a/llvm/utils/lit/lit/DiffUpdater.py b/llvm/utils/lit/lit/DiffUpdater.py
index 5bba2d70991df..fefcdcc99f3f2 100644
--- a/llvm/utils/lit/lit/DiffUpdater.py
+++ b/llvm/utils/lit/lit/DiffUpdater.py
@@ -1,6 +1,7 @@
 import shutil
 import os
 import shlex
+import pathlib
 
 """
 This file provides the `
diff _test_updater` function, which is invoked on failed RUN lines when lit is executed with --update-tests.
@@ -76,14 +77,12 @@ def get_target_dir(commands, test_path):
 
     @staticmethod
     def create(path, commands, test_path, target_dir):
-        filename = path.replace(target_dir, "")
-        if filename.startswith(os.sep):
-            filename = filename[len(os.sep) :]
+        path = pathlib.Path(path)
         with open(test_path, "r") as f:
             lines = f.readlines()
         for i, l in enumerate(lines):
             p = SplitFileTarget._get_split_line_path(l)
-            if p == filename:
+            if p and path.samefile(os.path.join(target_dir, p)):
                 idx = i
                 break
         else:


        


More information about the llvm-commits mailing list