summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Langmuir <blangmuir@apple.com>2014-03-05 19:56:30 +0000
committerBen Langmuir <blangmuir@apple.com>2014-03-05 19:56:30 +0000
commit82d372e12bc20de0a37c23a9a1f288f4fda0dae2 (patch)
tree177963a51c5bf470d612b74b336de84770e00701
parent4d36f91c0852c2c054056fa9bab7f6c443a82bb6 (diff)
downloadllvm-82d372e12bc20de0a37c23a9a1f288f4fda0dae2.tar.gz
llvm-82d372e12bc20de0a37c23a9a1f288f4fda0dae2.tar.bz2
llvm-82d372e12bc20de0a37c23a9a1f288f4fda0dae2.tar.xz
Fix an inconsistency in treatment of trailing / in path::const_iterator
When using a //net/ path, we were transforming the trailing / into a '.' when the path was just the root path and we were iterating backwards. Forwards iteration and other kinds of root path (C:\, /) were already correct. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202999 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Support/Path.cpp13
-rw-r--r--unittests/Support/Path.cpp29
2 files changed, 34 insertions, 8 deletions
diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp
index 1bd94a76fa..6fdad22158 100644
--- a/lib/Support/Path.cpp
+++ b/lib/Support/Path.cpp
@@ -307,21 +307,18 @@ const_iterator &const_iterator::operator++() {
}
const_iterator &const_iterator::operator--() {
- // If we're at the end and the previous char was a '/', return '.'.
+ // If we're at the end and the previous char was a '/', return '.' unless
+ // we are the root path.
+ size_t root_dir_pos = root_dir_start(Path);
if (Position == Path.size() &&
- Path.size() > 1 &&
- is_separator(Path[Position - 1])
-#ifdef LLVM_ON_WIN32
- && Path[Position - 2] != ':'
-#endif
- ) {
+ Path.size() > root_dir_pos + 1 &&
+ is_separator(Path[Position - 1])) {
--Position;
Component = ".";
return *this;
}
// Skip separators unless it's the root directory.
- size_t root_dir_pos = root_dir_start(Path);
size_t end_pos = Position;
while(end_pos > 0 &&
diff --git a/unittests/Support/Path.cpp b/unittests/Support/Path.cpp
index c4067b9137..29a77f3780 100644
--- a/unittests/Support/Path.cpp
+++ b/unittests/Support/Path.cpp
@@ -210,6 +210,35 @@ TEST(Support, AbsolutePathIteratorWin32) {
}
#endif // LLVM_ON_WIN32
+TEST(Support, AbsolutePathIteratorEnd) {
+ // Trailing slashes are converted to '.' unless they are part of the root path.
+ SmallVector<StringRef, 4> Paths;
+ Paths.push_back("/foo/");
+ Paths.push_back("/foo//");
+ Paths.push_back("//net//");
+#ifdef LLVM_ON_WIN32
+ Paths.push_back("c:\\\\");
+#endif
+
+ for (StringRef Path : Paths) {
+ StringRef LastComponent = *--path::end(Path);
+ EXPECT_EQ(".", LastComponent);
+ }
+
+ SmallVector<StringRef, 3> RootPaths;
+ RootPaths.push_back("/");
+ RootPaths.push_back("//net/");
+#ifdef LLVM_ON_WIN32
+ RootPaths.push_back("c:\\");
+#endif
+
+ for (StringRef Path : RootPaths) {
+ StringRef LastComponent = *--path::end(Path);
+ EXPECT_EQ(1u, LastComponent.size());
+ EXPECT_TRUE(path::is_separator(LastComponent[0]));
+ }
+}
+
TEST(Support, HomeDirectory) {
#ifdef LLVM_ON_UNIX
// This test only makes sense on Unix if $HOME is set.