[llvm] Fix Windows Path Separator issues in create_symlink and readlink (PR #206665)

Junji Watanabe via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 30 00:16:26 PDT 2026


https://github.com/Jwata created https://github.com/llvm/llvm-project/pull/206665

- Force create_symlink target path to use backslashes on Windows, as NTFS reparse points require backslashes.
- Normalize readlink output to native path separators to match preferred style.

This fixes the following test failure:

```
PS C:\src\chromium\src\third_party\llvm> .\build_repro\unittests\Support\SupportTests.exe --gtest_filter=FileSystemTest.CreateRelativeDirectorySymlink
[ RUN      ] FileSystemTest.CreateRelativeDirectorySymlink
Test Directory: C:/src/temp/file-system-test-a3fd42
C:\src\chromium\src\third_party\llvm\llvm\unittests\Support\Path.cpp(896): error: Value of: fs::is_directory(Link)                                                                                                                                                                                                                     Actual: false
Expected: true
```                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

>From 33ab60ac1097c82c286c4df93487a9d32bb5b0e3 Mon Sep 17 00:00:00 2001
From: Junji Watanabe <jwata at google.com>
Date: Thu, 25 Jun 2026 16:56:44 +0900
Subject: [PATCH] Fix Windows Path Separator issues in create_symlink and
 readlink

- Force create_symlink target path to use backslashes on Windows, as NTFS reparse points require backslashes.

- Normalize readlink output to native path separators to match preferred style.
---
 llvm/lib/Support/Windows/Path.inc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc
index b4be1c2d6f5c2..d149cd4476b11 100644
--- a/llvm/lib/Support/Windows/Path.inc
+++ b/llvm/lib/Support/Windows/Path.inc
@@ -342,7 +342,7 @@ std::error_code create_symlink(const Twine &to, const Twine &from) {
   // The Win32 API normally allows forward slashes, but under some cases it does
   // not correctly handle them in the target of a symlink.
   SmallString<128> ToStr;
-  llvm::sys::path::native(to, ToStr);
+  llvm::sys::path::native(to, ToStr, llvm::sys::path::Style::windows_backslash);
 
   SmallVector<wchar_t, 128> WideFrom;
   SmallVector<wchar_t, 128> WideTo;
@@ -1819,6 +1819,7 @@ std::error_code readlink(const Twine &path, SmallVectorImpl<char> &dest) {
   if (std::error_code EC = UTF16ToUTF8(Target, TargetLen, dest))
     return EC;
 
+  llvm::sys::path::native(dest);
   return std::error_code();
 }
 



More information about the llvm-commits mailing list