[llvm] [Windows][test] Fix "LLVM" test failures when LLVM_WINDOWS_PREFER_FORWARD_SLASH is ON (PR #184556)

via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 4 13:50:55 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-support

Author: Junji Watanabe (Jwata)

<details>
<summary>Changes</summary>

This patch fixes several LLVM test failures on Windows that occur when the LLVM_WINDOWS_PREFER_FORWARD_SLASH CMake option is enabled.

The failures were caused by tests either hardcoding backslash expectations in FileCheck or constructing paths with strict backslashes in C++ unit tests, both of which break when the environment is configured to prefer forward slashes.

Specific changes:
- `llvm-cov` and `llvm-objdump` lit tests: Relaxed FileCheck patterns (in `directory_coverage.win.test`, `native_separators.c`, and `source-interleave-prefix-windows.test`) to accept either forward or backward slashes using the `{{[/\\]}}` regex. This makes the path matching resilient to the underlying separator preference without losing precision.
- CommandLineTest.cpp: Conditionalized the TestRoot variable to use `C:/` instead of `C:\` based on the build configuration.
- Path.cpp (makeLongFormPath test):
  - Updated the OneDir string literal to conditionally use `/` or `\`.
  - Updated the ContainsDotAndDotDot lambda to check for `.` and `..` components with the correct separator style based on the build configuration.

---
Full diff: https://github.com/llvm/llvm-project/pull/184556.diff


5 Files Affected:

- (modified) llvm/test/tools/llvm-cov/directory_coverage.win.test (+4-4) 
- (modified) llvm/test/tools/llvm-cov/native_separators.c (+3-3) 
- (modified) llvm/test/tools/llvm-objdump/X86/source-interleave-prefix-windows.test (+1-1) 
- (modified) llvm/unittests/Support/CommandLineTest.cpp (+2-2) 
- (modified) llvm/unittests/Support/Path.cpp (+6-1) 


``````````diff
diff --git a/llvm/test/tools/llvm-cov/directory_coverage.win.test b/llvm/test/tools/llvm-cov/directory_coverage.win.test
index f948bdcae3a58..739375a037f48 100644
--- a/llvm/test/tools/llvm-cov/directory_coverage.win.test
+++ b/llvm/test/tools/llvm-cov/directory_coverage.win.test
@@ -23,13 +23,13 @@
 
 
 
-# HTML-TOP: coverage\index.html
+# HTML-TOP: coverage{{[/\\]}}index.html
 
-# ROOT: a0\a1\a2.cc
-# ROOT: b0\
+# ROOT: a0{{[/\\]}}a1{{[/\\]}}a2.cc
+# ROOT: b0{{[/\\]}}
 # ROOT-NOT: b1_1.cc
 # ROOT-NOT: b1_2.cc
-# ROOT: c0\c1\
+# ROOT: c0{{[/\\]}}c1{{[/\\]}}
 # ROOT-NOT: c2_1.cc
 # ROOT-NOT: b2_2.cc
 # ROOT: main.cc
diff --git a/llvm/test/tools/llvm-cov/native_separators.c b/llvm/test/tools/llvm-cov/native_separators.c
index 3c768e1014b92..b6ad175aa8f33 100644
--- a/llvm/test/tools/llvm-cov/native_separators.c
+++ b/llvm/test/tools/llvm-cov/native_separators.c
@@ -13,8 +13,8 @@
 // RUN: llvm-cov show -format=html %S/Inputs/native_separators.covmapping -instr-profile=%t.profdata -path-equivalence=/tmp,%S %s -o %t.dir
 // RUN: FileCheck -check-prefixes=HTML -input-file=%t.dir/coverage/tmp/native_separators.c.html %s
 
-// TEXT-INDEX: \tmp\native_separators.c
-// HTML-INDEX: >tmp\native_separators.c</a>
-// HTML: <pre>\tmp\native_separators.c</pre>
+// TEXT-INDEX: {{[/\\]}}tmp{{[/\\]}}native_separators.c
+// HTML-INDEX: >tmp{{[/\\]}}native_separators.c</a>
+// HTML: <pre>{{[/\\]}}tmp{{[/\\]}}native_separators.c</pre>
 
 int main() {}
diff --git a/llvm/test/tools/llvm-objdump/X86/source-interleave-prefix-windows.test b/llvm/test/tools/llvm-objdump/X86/source-interleave-prefix-windows.test
index 0f8952daec42e..db5265b26d5a3 100644
--- a/llvm/test/tools/llvm-objdump/X86/source-interleave-prefix-windows.test
+++ b/llvm/test/tools/llvm-objdump/X86/source-interleave-prefix-windows.test
@@ -7,5 +7,5 @@
 ; RUN: sed -e "s,SRC_COMPDIR,/Inputs,g" %p/Inputs/source-interleave.ll > %t.ll
 ; RUN: llc -o %t.o -filetype=obj -mtriple=x86_64-pc-linux %t.ll
 ; RUN: llvm-objdump --prefix 'myprefix/\' --source %t.o 2>&1 | FileCheck %s -DFILE=%t.o -DPREFIX='myprefix'
-; CHECK: warning: '[[FILE]]': failed to find source [[PREFIX]]/Inputs\source-interleave-x86_64.c
+; CHECK: warning: '[[FILE]]': failed to find source [[PREFIX]]{{[/\\]}}Inputs{{[/\\]}}source-interleave-x86_64.c
 
diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp
index 9e8a165fe136f..2f91c2ac8c1f0 100644
--- a/llvm/unittests/Support/CommandLineTest.cpp
+++ b/llvm/unittests/Support/CommandLineTest.cpp
@@ -950,7 +950,7 @@ TEST(CommandLineTest, ResponseFiles) {
 TEST(CommandLineTest, RecursiveResponseFiles) {
   vfs::InMemoryFileSystem FS;
 #ifdef _WIN32
-  const char *TestRoot = "C:\\";
+  const char *TestRoot = LLVM_WINDOWS_PREFER_FORWARD_SLASH ? "C:/" : "C:\\";
 #else
   const char *TestRoot = "/";
 #endif
@@ -1020,7 +1020,7 @@ TEST(CommandLineTest, RecursiveResponseFiles) {
 TEST(CommandLineTest, ResponseFilesAtArguments) {
   vfs::InMemoryFileSystem FS;
 #ifdef _WIN32
-  const char *TestRoot = "C:\\";
+  const char *TestRoot = LLVM_WINDOWS_PREFER_FORWARD_SLASH ? "C:/" : "C:\\";
 #else
   const char *TestRoot = "/";
 #endif
diff --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp
index b27ed6f950b10..984e99024c484 100644
--- a/llvm/unittests/Support/Path.cpp
+++ b/llvm/unittests/Support/Path.cpp
@@ -11,6 +11,7 @@
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/BinaryFormat/Magic.h"
+#include "llvm/Config/config.h"
 #include "llvm/Config/llvm-config.h" // for LLVM_ON_UNIX
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ConvertUTF.h"
@@ -2584,7 +2585,9 @@ TEST_F(FileSystemTest, makeLongFormPath) {
 
   // Setup: A test directory longer than 8 characters for which a distinct
   // short 8.3 form name will be created on Windows. Typically, 123456~1.
-  constexpr const char *OneDir = "\\123456789"; // >8 chars
+  const char *OneDir = LLVM_WINDOWS_PREFER_FORWARD_SLASH
+                           ? "/123456789"
+                           : "\\123456789"; // >8 chars
 
   // Setup: Create a path where even if all components were reduced to short 8.3
   // form names, the total length would exceed MAX_PATH.
@@ -2617,6 +2620,8 @@ TEST_F(FileSystemTest, makeLongFormPath) {
   ASSERT_FALSE(DotAndDotDot.empty())
       << "Expected short 8.3 form path for test directory.";
   auto ContainsDotAndDotDot = [](llvm::StringRef S) {
+    if (LLVM_WINDOWS_PREFER_FORWARD_SLASH)
+      return S.contains("/./") && S.contains("/../");
     return S.contains("\\.\\") && S.contains("\\..\\");
   };
   ASSERT_TRUE(ContainsDotAndDotDot(DotAndDotDot))

``````````

</details>


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


More information about the llvm-commits mailing list