[lld] [llvm] [LIT] Use forward slashes in substitutions when LLVM_WINDOWS_PREFER_FORWARD_SLASH is set (PR #179865)

Junji Watanabe via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 16 22:01:13 PST 2026


https://github.com/Jwata updated https://github.com/llvm/llvm-project/pull/179865

>From c8cc8f03609b9bce42e4032bed785eb854ce16c0 Mon Sep 17 00:00:00 2001
From: Junji Watanabe <jwata at google.com>
Date: Tue, 3 Feb 2026 13:06:36 +0900
Subject: [PATCH 1/4] [LIT][LLD] Fix Windows test failures due to path
 separator mismatches

When building with -DLLVM_WINDOWS_PREFER_FORWARD_SLASH=ON, tools like lld output paths with forward slashes on Windows. However, lit's default substitutions (%t, %p) typically use backslashes on Windows, causing FileCheck failures in tests that strictly match path separators.
---
 lld/test/COFF/linkreprofullpathrsp.test | 2 +-
 llvm/utils/lit/lit/TestRunner.py        | 6 +++++-
 llvm/utils/llvm-lit/llvm-lit.in         | 3 +++
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/lld/test/COFF/linkreprofullpathrsp.test b/lld/test/COFF/linkreprofullpathrsp.test
index 66f2e2ba2f859..4d6f0a8a90f1a 100644
--- a/lld/test/COFF/linkreprofullpathrsp.test
+++ b/lld/test/COFF/linkreprofullpathrsp.test
@@ -14,7 +14,7 @@ Test link.exe-style /linkreprofullpathrsp: flag.
 # RUN: lld-link /subsystem:console %t.obj %p/Inputs/std32.lib /defaultlib:%p/Inputs/library.lib \
 # RUN:  /libpath:%p/Inputs /defaultlib:std64.lib ret42.lib /entry:main at 0 /linkreprofullpathrsp:%t.rsp \
 # RUN:   %t.pdb /wholearchive:%t.archive.lib /out:%t.exe /timestamp:0
-# # RUN: FileCheck %s --check-prefix=RSP -DT=%t -DP=%p < %t.rsp
+# RUN: FileCheck %s --check-prefix=RSP -DT=%t -DP=%p < %t.rsp
 
 # RUN: lld-link /subsystem:console @%t.rsp /out:%t2.exe /entry:main at 0 /timestamp:0
 # RUN: diff %t.exe %t2.exe
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index 2683180d2864d..01f14bad315de 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -2457,7 +2457,11 @@ def executeShTest(
     tmpDir, tmpBase = getTempPaths(test)
     substitutions = list(extra_substitutions)
     substitutions += getDefaultSubstitutions(
-        test, tmpDir, tmpBase, normalize_slashes=useExternalSh
+        test,
+        tmpDir,
+        tmpBase,
+        normalize_slashes=useExternalSh
+        or litConfig.params.get("use_normalized_slashes", False),
     )
     conditions = {feature: True for feature in test.config.available_features}
     script = applySubstitutions(
diff --git a/llvm/utils/llvm-lit/llvm-lit.in b/llvm/utils/llvm-lit/llvm-lit.in
index 0b6683b6b6230..62ee5bf21fc60 100755
--- a/llvm/utils/llvm-lit/llvm-lit.in
+++ b/llvm/utils/llvm-lit/llvm-lit.in
@@ -17,6 +17,9 @@ def map_config(source_dir, site_config):
 # configuration file knows how to find the object tree.
 builtin_parameters = { 'build_mode' : '@BUILD_MODE@' }
 
+if "@LLVM_WINDOWS_PREFER_FORWARD_SLASH@".upper() in ["ON", "TRUE", "1"]:
+    builtin_parameters["use_normalized_slashes"] = True
+
 @LLVM_LIT_CONFIG_MAP@
 
 builtin_parameters['config_map'] = config_map

>From 57b409ca2b408b29bd273c812d6bec06375940c5 Mon Sep 17 00:00:00 2001
From: Junji Watanabe <jwata at google.com>
Date: Fri, 6 Feb 2026 11:52:40 +0900
Subject: [PATCH 2/4] Address code reviews - revert comment out fix - use
 lit.util.pythonize_bool()

---
 lld/test/COFF/linkreprofullpathrsp.test | 2 +-
 llvm/utils/llvm-lit/llvm-lit.in         | 8 +++++---
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/lld/test/COFF/linkreprofullpathrsp.test b/lld/test/COFF/linkreprofullpathrsp.test
index 4d6f0a8a90f1a..66f2e2ba2f859 100644
--- a/lld/test/COFF/linkreprofullpathrsp.test
+++ b/lld/test/COFF/linkreprofullpathrsp.test
@@ -14,7 +14,7 @@ Test link.exe-style /linkreprofullpathrsp: flag.
 # RUN: lld-link /subsystem:console %t.obj %p/Inputs/std32.lib /defaultlib:%p/Inputs/library.lib \
 # RUN:  /libpath:%p/Inputs /defaultlib:std64.lib ret42.lib /entry:main at 0 /linkreprofullpathrsp:%t.rsp \
 # RUN:   %t.pdb /wholearchive:%t.archive.lib /out:%t.exe /timestamp:0
-# RUN: FileCheck %s --check-prefix=RSP -DT=%t -DP=%p < %t.rsp
+# # RUN: FileCheck %s --check-prefix=RSP -DT=%t -DP=%p < %t.rsp
 
 # RUN: lld-link /subsystem:console @%t.rsp /out:%t2.exe /entry:main at 0 /timestamp:0
 # RUN: diff %t.exe %t2.exe
diff --git a/llvm/utils/llvm-lit/llvm-lit.in b/llvm/utils/llvm-lit/llvm-lit.in
index 62ee5bf21fc60..62d42e062e041 100755
--- a/llvm/utils/llvm-lit/llvm-lit.in
+++ b/llvm/utils/llvm-lit/llvm-lit.in
@@ -17,9 +17,6 @@ def map_config(source_dir, site_config):
 # configuration file knows how to find the object tree.
 builtin_parameters = { 'build_mode' : '@BUILD_MODE@' }
 
-if "@LLVM_WINDOWS_PREFER_FORWARD_SLASH@".upper() in ["ON", "TRUE", "1"]:
-    builtin_parameters["use_normalized_slashes"] = True
-
 @LLVM_LIT_CONFIG_MAP@
 
 builtin_parameters['config_map'] = config_map
@@ -28,6 +25,11 @@ builtin_parameters['config_map'] = config_map
 llvm_source_root = path(r'@LLVM_SOURCE_DIR@')
 sys.path.insert(0, os.path.join(llvm_source_root, 'utils', 'lit'))
 
+import lit.util
+
+if lit.util.pythonize_bool('@LLVM_WINDOWS_PREFER_FORWARD_SLASH@'):
+    builtin_parameters['use_normalized_slashes'] = True
+
 if __name__=='__main__':
     from lit.main import main
     main(builtin_parameters)

>From 983c49a145636a650e9ccd4b361167c106ea10da Mon Sep 17 00:00:00 2001
From: Junji Watanabe <jwata at google.com>
Date: Fri, 6 Feb 2026 22:32:44 +0900
Subject: [PATCH 3/4] fix other substitutions to respect
 normalized_slashes=True

---
 llvm/utils/lit/lit/TestRunner.py | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index 01f14bad315de..606f7f936ef51 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -1525,11 +1525,25 @@ def getDefaultSubstitutions(test, tmpDir, tmpBase, normalize_slashes=False):
     substitutions.append(("%{s:basename}", sourceBaseName))
     substitutions.append(("%{t:stem}", tmpBaseName))
 
+    fs_sep = os.path.sep
+    if normalize_slashes:
+        fs_sep = "/"
+
     substitutions.extend(
         [
-            ("%{fs-src-root}", pathlib.Path(sourcedir).anchor),
-            ("%{fs-tmp-root}", pathlib.Path(tmpBase).anchor),
-            ("%{fs-sep}", os.path.sep),
+            (
+                "%{fs-src-root}",
+                pathlib.Path(sourcedir).anchor.replace("\\", "/")
+                if normalize_slashes
+                else pathlib.Path(sourcedir).anchor,
+            ),
+            (
+                "%{fs-tmp-root}",
+                pathlib.Path(tmpBase).anchor.replace("\\", "/")
+                if normalize_slashes
+                else pathlib.Path(tmpBase).anchor,
+            ),
+            ("%{fs-sep}", fs_sep),
         ]
     )
 

>From 5f8c1f1f8f234ee3bca7dde249d7b5397c5551f5 Mon Sep 17 00:00:00 2001
From: Junji Watanabe <jwata at google.com>
Date: Tue, 17 Feb 2026 15:00:50 +0900
Subject: [PATCH 4/4] relax path maches for lit tests

---
 llvm/utils/lit/tests/shtest-readfile.py | 6 +++---
 llvm/utils/lit/tests/use-llvm-tool.py   | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/llvm/utils/lit/tests/shtest-readfile.py b/llvm/utils/lit/tests/shtest-readfile.py
index ca57db82e6617..26ea2911f96f2 100644
--- a/llvm/utils/lit/tests/shtest-readfile.py
+++ b/llvm/utils/lit/tests/shtest-readfile.py
@@ -3,13 +3,13 @@
 # TODO(boomanaiden154): This sometimes fails, possibly due to buffers not being flushed.
 # ALLOW_RETRIES: 2
 
-# RUN: env LIT_USE_INTERNAL_SHELL=1  not %{lit} -v %{inputs}/shtest-readfile | FileCheck -match-full-lines -DTEMP_PATH=%S%{fs-sep}Inputs%{fs-sep}shtest-readfile%{fs-sep}Output %s
+# RUN: env LIT_USE_INTERNAL_SHELL=1  not %{lit} -v %{inputs}/shtest-readfile | FileCheck -match-full-lines %s
 
 # CHECK: -- Testing: 5 tests{{.*}}
 
 # CHECK-LABEL: FAIL: shtest-readfile :: absolute-paths.txt ({{[^)]*}})
 # CHECK: echo hello
-# CHECK: # executed command: echo '%{readfile:[[TEMP_PATH]]{{[\\\/]}}absolute-paths.txt.tmp}'
+# CHECK: # executed command: echo '%{readfile:{{.*}}absolute-paths.txt.tmp}'
 
 # CHECK-LABEL: FAIL: shtest-readfile :: env.txt ({{[^)]*}})
 # CHECK: env TEST=hello {{.*}} -c "import os; print(os.environ['TEST'])"
@@ -25,4 +25,4 @@
 
 # CHECK-LABEL: FAIL: shtest-readfile :: two-same-line.txt ({{[^)]*}})
 # CHECK: echo hello bye
-# CHECK: # executed command: echo '%{readfile:[[TEMP_PATH]]{{[\\\/]}}two-same-line.txt.tmp.1}' '%{readfile:[[TEMP_PATH]]{{[\\\/]}}two-same-line.txt.tmp.2}'
+# CHECK: # executed command: echo '%{readfile:{{.*}}two-same-line.txt.tmp.1}' '%{readfile:{{.*}}two-same-line.txt.tmp.2}'
diff --git a/llvm/utils/lit/tests/use-llvm-tool.py b/llvm/utils/lit/tests/use-llvm-tool.py
index 3e190a3e40f71..cfaa976ff1314 100644
--- a/llvm/utils/lit/tests/use-llvm-tool.py
+++ b/llvm/utils/lit/tests/use-llvm-tool.py
@@ -5,7 +5,7 @@
 ## 3) The PATH, if requested.
 
 # RUN: %{lit} %{inputs}/use-llvm-tool 2>&1 | \
-# RUN:   FileCheck %s -DDIR=%p
+# RUN:   FileCheck %s
 
 ## The exact breakdown of cases is:
 ## Case | Env | Build Dir | PATH |
@@ -22,7 +22,7 @@
 
 ## Check the exact path reported for the first case, but don't bother for the
 ## others.
-# CHECK:      note: using case1: [[DIR]]{{[\\/]}}Inputs{{[\\/]}}use-llvm-tool{{[\\/]}}env-case1
+# CHECK:      note: using case1: {{.*}}{{[\\/]}}Inputs{{[\\/]}}use-llvm-tool{{[\\/]}}env-case1
 # CHECK-NEXT: note: using case2: {{.*}}build{{[\\/]}}case2
 # CHECK-NEXT: note: using case3: {{.*}}build{{[\\/]}}case3
 # CHECK-NEXT: note: using case4: {{.*}}path{{[\\/]}}case4



More information about the llvm-commits mailing list