[llvm] r332508 - Fix llvm::sys::path::remove_dots() to return "." instead of an empty path.
Greg Clayton via llvm-commits
llvm-commits at lists.llvm.org
Wed May 16 11:25:51 PDT 2018
Author: gclayton
Date: Wed May 16 11:25:51 2018
New Revision: 332508
URL: http://llvm.org/viewvc/llvm-project?rev=332508&view=rev
Log:
Fix llvm::sys::path::remove_dots() to return "." instead of an empty path.
Differential Revision: https://reviews.llvm.org/D46887
Modified:
llvm/trunk/lib/Support/Path.cpp
llvm/trunk/unittests/Support/Path.cpp
Modified: llvm/trunk/lib/Support/Path.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Path.cpp?rev=332508&r1=332507&r2=332508&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Path.cpp (original)
+++ llvm/trunk/lib/Support/Path.cpp Wed May 16 11:25:51 2018
@@ -726,6 +726,10 @@ static SmallString<256> remove_dots(Stri
SmallString<256> buffer = path::root_path(path, style);
for (StringRef C : components)
path::append(buffer, style, C);
+ // If the buffer is empty, then return ".". Many other path utilities
+ // do this so it seems to be an expected result.
+ if (buffer.empty())
+ buffer.append(1, '.');
return buffer;
}
Modified: llvm/trunk/unittests/Support/Path.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/Path.cpp?rev=332508&r1=332507&r2=332508&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/Path.cpp (original)
+++ llvm/trunk/unittests/Support/Path.cpp Wed May 16 11:25:51 2018
@@ -1146,7 +1146,7 @@ static std::string remove_dots(StringRef
TEST(Support, RemoveDots) {
EXPECT_EQ("foolz\\wat",
remove_dots(".\\.\\\\foolz\\wat", false, path::Style::windows));
- EXPECT_EQ("", remove_dots(".\\\\\\\\\\", false, path::Style::windows));
+ EXPECT_EQ(".", remove_dots(".\\\\\\\\\\", false, path::Style::windows));
EXPECT_EQ("a\\..\\b\\c",
remove_dots(".\\a\\..\\b\\c", false, path::Style::windows));
@@ -1163,7 +1163,8 @@ TEST(Support, RemoveDots) {
EXPECT_EQ("foolz/wat",
remove_dots("././/foolz/wat", false, path::Style::posix));
- EXPECT_EQ("", remove_dots("./////", false, path::Style::posix));
+ EXPECT_EQ(".", remove_dots("./////", false, path::Style::posix));
+ EXPECT_EQ(".", remove_dots("", false, path::Style::posix));
EXPECT_EQ("a/../b/c", remove_dots("./a/../b/c", false, path::Style::posix));
EXPECT_EQ("b/c", remove_dots("./a/../b/c", true, path::Style::posix));
More information about the llvm-commits
mailing list