Skip to content

Commit d4abec6

Browse files
author
git apple-llvm automerger
committed
Merge commit 'f6eb5daa1636' from llvm.org/master into apple/master
2 parents 0f31802 + f6eb5da commit d4abec6

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

llvm/lib/Support/Windows/Path.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -957,9 +957,9 @@ std::error_code detail::directory_iterator_construct(detail::DirIterState &IT,
957957
return EC;
958958

959959
// Convert path to the format that Windows is happy with.
960-
if (PathUTF16.size() > 0 &&
961-
!is_separator(PathUTF16[Path.size() - 1]) &&
962-
PathUTF16[Path.size() - 1] != L':') {
960+
size_t PathUTF16Len = PathUTF16.size();
961+
if (PathUTF16Len > 0 && !is_separator(PathUTF16[PathUTF16Len - 1]) &&
962+
PathUTF16[PathUTF16Len - 1] != L':') {
963963
PathUTF16.push_back(L'\\');
964964
PathUTF16.push_back(L'*');
965965
} else {

llvm/unittests/Support/Path.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,39 @@ TEST_F(FileSystemTest, BrokenSymlinkDirectoryIteration) {
11491149
}
11501150
#endif
11511151

1152+
#ifdef _WIN32
1153+
TEST_F(FileSystemTest, UTF8ToUTF16DirectoryIteration) {
1154+
// The Windows filesystem support uses UTF-16 and converts paths from the
1155+
// input UTF-8. The UTF-16 equivalent of the input path can be shorter in
1156+
// length.
1157+
1158+
// This test relies on TestDirectory not being so long such that MAX_PATH
1159+
// would be exceeded (see widenPath). If that were the case, the UTF-16
1160+
// path is likely to be longer than the input.
1161+
const char *Pi = "\xcf\x80"; // UTF-8 lower case pi.
1162+
std::string RootDir = (TestDirectory + "/" + Pi).str();
1163+
1164+
// Create test directories.
1165+
ASSERT_NO_ERROR(fs::create_directories(Twine(RootDir) + "/a"));
1166+
ASSERT_NO_ERROR(fs::create_directories(Twine(RootDir) + "/b"));
1167+
1168+
std::error_code EC;
1169+
unsigned Count = 0;
1170+
for (fs::directory_iterator I(Twine(RootDir), EC), E; I != E;
1171+
I.increment(EC)) {
1172+
ASSERT_NO_ERROR(EC);
1173+
StringRef DirName = path::filename(I->path());
1174+
EXPECT_TRUE(DirName == "a" || DirName == "b");
1175+
++Count;
1176+
}
1177+
EXPECT_EQ(Count, 2U);
1178+
1179+
ASSERT_NO_ERROR(fs::remove(Twine(RootDir) + "/a"));
1180+
ASSERT_NO_ERROR(fs::remove(Twine(RootDir) + "/b"));
1181+
ASSERT_NO_ERROR(fs::remove(Twine(RootDir)));
1182+
}
1183+
#endif
1184+
11521185
TEST_F(FileSystemTest, Remove) {
11531186
SmallString<64> BaseDir;
11541187
SmallString<64> Paths[4];

0 commit comments

Comments
 (0)