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 Path16; - std::error_code EC = widenPath(path, Path16); + std::error_code EC = widenPath(NativePath, Path16); if (EC && !IgnoreErrors) return EC; 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)); }