[llvm] [llvm][Support][Windows] Fix slash in path for remove_directories (PR #121448)
Jinsong Ji via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 2 08:27:47 PST 2025
https://github.com/jsji updated https://github.com/llvm/llvm-project/pull/121448
>From af2c1659a0df738b37655c82cfab48414ff1004e Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Wed, 1 Jan 2025 19:26:46 -0800
Subject: [PATCH 1/2] [llvm][Support][Windows] Fix slash in path for
remove_directories
Before 925471ed903dad871042d7ed0bab89ab6566a564 remove_directories
supports path with slash (instead of backslash).
The ILCreateFromPathW in new implementation requirs backslash path,
so the call to remove_directories will fail if the path contains slash.
This is to normalize the path to make sure remove_directories still
support path with slash as well.
---
llvm/lib/Support/Windows/Path.inc | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc
index 17db114caeb1ec..5b311e7c475c56 100644
--- a/llvm/lib/Support/Windows/Path.inc
+++ b/llvm/lib/Support/Windows/Path.inc
@@ -1373,9 +1373,11 @@ std::error_code closeFile(file_t &F) {
}
std::error_code remove_directories(const Twine &path, bool IgnoreErrors) {
+ SmallString<128> NativePath;
+ llvm::sys::path::native(path, NativePath, path::Style::windows_backslash);
// Convert to utf-16.
SmallVector<wchar_t, 128> Path16;
- std::error_code EC = widenPath(path, Path16);
+ std::error_code EC = widenPath(NativePath, Path16);
if (EC && !IgnoreErrors)
return EC;
>From 7e72bcabb9dfb212024ba4eacf2c7bf9d8b19708 Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Thu, 2 Jan 2025 08:27:27 -0800
Subject: [PATCH 2/2] Fix the unittest about remove_directories
---
llvm/unittests/Support/Path.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp
index 8dde2fb50160c9..187f47d9cfe078 100644
--- a/llvm/unittests/Support/Path.cpp
+++ b/llvm/unittests/Support/Path.cpp
@@ -1326,6 +1326,9 @@ TEST_F(FileSystemTest, Remove) {
ASSERT_NO_ERROR(fs::remove_directories("D:/footest"));
+ ASSERT_NO_ERROR(fs::remove_directories(Twine(BaseDir) + "/foo/bar/baz"));
+ ASSERT_FALSE(fs::exists(Twine(BaseDir) + "/foo/bar/baz"));
+
ASSERT_NO_ERROR(fs::remove_directories(BaseDir));
ASSERT_FALSE(fs::exists(BaseDir));
}
More information about the llvm-commits
mailing list