[llvm] r202999 - Fix an inconsistency in treatment of trailing / in path::const_iterator
Ben Langmuir
blangmuir at apple.com
Wed Mar 5 11:56:30 PST 2014
Author: benlangmuir
Date: Wed Mar 5 13:56:30 2014
New Revision: 202999
URL: http://llvm.org/viewvc/llvm-project?rev=202999&view=rev
Log:
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.
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=202999&r1=202998&r2=202999&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Path.cpp (original)
+++ llvm/trunk/lib/Support/Path.cpp Wed Mar 5 13:56:30 2014
@@ -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 &&
Modified: llvm/trunk/unittests/Support/Path.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/Path.cpp?rev=202999&r1=202998&r2=202999&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/Path.cpp (original)
+++ llvm/trunk/unittests/Support/Path.cpp Wed Mar 5 13:56:30 2014
@@ -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.
More information about the llvm-commits
mailing list