https://github.com/zeyi2 created 
https://github.com/llvm/llvm-project/pull/207499

None

>From 247afadb3971244f036f86c58267c6b158f6644d Mon Sep 17 00:00:00 2001
From: Zeyi Xu <[email protected]>
Date: Sat, 4 Jul 2026 16:57:31 +0800
Subject: [PATCH] [Tooling] Preserve backslashes in POSIX source paths

---
 clang/lib/Tooling/Tooling.cpp           |  2 +-
 clang/unittests/Tooling/ToolingTest.cpp | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index 5da9c31ec47ec..71307d1fe7307 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -260,7 +260,7 @@ llvm::Expected<std::string> 
getAbsolutePath(llvm::vfs::FileSystem &FS,
   SmallString<1024> AbsolutePath = RelativePath;
   if (auto EC = FS.makeAbsolute(AbsolutePath))
     return llvm::errorCodeToError(EC);
-  llvm::sys::path::native(AbsolutePath);
+  llvm::sys::path::make_preferred(AbsolutePath);
   return std::string(AbsolutePath);
 }
 
diff --git a/clang/unittests/Tooling/ToolingTest.cpp 
b/clang/unittests/Tooling/ToolingTest.cpp
index c3b8ffa00924e..aee46dc2e2c63 100644
--- a/clang/unittests/Tooling/ToolingTest.cpp
+++ b/clang/unittests/Tooling/ToolingTest.cpp
@@ -686,6 +686,26 @@ TEST(runToolOnCodeWithArgs, DiagnosticsColor) {
       {"-fcolor-diagnostics"}));
 }
 
+#if !defined(_WIN32)
+TEST(getAbsolutePath, PosixPreservesBackslashes) {
+  auto FS = llvm::vfs::getRealFileSystem();
+  llvm::Expected<std::string> Path = getAbsolutePath(*FS, "a\\b.cc");
+  if (!Path)
+    FAIL() << llvm::toString(Path.takeError());
+
+  llvm::ErrorOr<std::string> CWD = FS->getCurrentWorkingDirectory();
+  ASSERT_TRUE(CWD) << CWD.getError().message();
+
+  SmallString<128> Expected(*CWD);
+  llvm::sys::path::append(Expected, "a\\b.cc");
+  SmallString<128> WithSlash(*CWD);
+  llvm::sys::path::append(WithSlash, "a/b.cc");
+
+  EXPECT_EQ(std::string(Expected), *Path);
+  EXPECT_NE(std::string(WithSlash), *Path);
+}
+#endif
+
 TEST(ClangToolTest, ArgumentAdjusters) {
   FixedCompilationDatabase Compilations("/", std::vector<std::string>());
 

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to