summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2018-05-16 18:25:51 +0000
committerGreg Clayton <gclayton@apple.com>2018-05-16 18:25:51 +0000
commitb24957e22a965535d34f8f987c8b4b6ccfcd5f69 (patch)
treeda5575659e2ca836f87fe248359bb7bc1016c321
parentd63396097d57b5d89c3f66b11bd427033a9c5e33 (diff)
downloadbcm5719-llvm-b24957e22a965535d34f8f987c8b4b6ccfcd5f69.tar.gz
bcm5719-llvm-b24957e22a965535d34f8f987c8b4b6ccfcd5f69.zip
Fix llvm::sys::path::remove_dots() to return "." instead of an empty path.
Differential Revision: https://reviews.llvm.org/D46887 llvm-svn: 332508
-rw-r--r--llvm/lib/Support/Path.cpp4
-rw-r--r--llvm/unittests/Support/Path.cpp5
2 files changed, 7 insertions, 2 deletions
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp
index ff41dd47c42..dfe9f470bab 100644
--- a/llvm/lib/Support/Path.cpp
+++ b/llvm/lib/Support/Path.cpp
@@ -726,6 +726,10 @@ static SmallString<256> remove_dots(StringRef path, bool remove_dot_dot,
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;
}
diff --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp
index e91f760f99f..1efa7715cac 100644
--- a/llvm/unittests/Support/Path.cpp
+++ b/llvm/unittests/Support/Path.cpp
@@ -1146,7 +1146,7 @@ static std::string remove_dots(StringRef path, bool remove_dot_dot,
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));
OpenPOWER on IntegriCloud