1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[Path] Fix bug in make_absolute logic

This fixes a bug for making path with a //net style root absolute. I
discovered the bug while writing a test case for the VFS, which uses
these paths because they're both legal absolute paths on Windows and
Unix.

Differential revision: https://reviews.llvm.org/D65675

llvm-svn: 368053
This commit is contained in:
Jonas Devlieghere 2019-08-06 15:46:45 +00:00
parent fec3a523d8
commit 29112a6576
2 changed files with 16 additions and 7 deletions

View File

@ -855,11 +855,11 @@ void make_absolute(const Twine &current_directory,
StringRef p(path.data(), path.size());
bool rootDirectory = path::has_root_directory(p);
bool rootName =
(real_style(Style::native) != Style::windows) || path::has_root_name(p);
bool rootName = path::has_root_name(p);
// Already absolute.
if (rootName && rootDirectory)
if ((rootName || real_style(Style::native) != Style::windows) &&
rootDirectory)
return;
// All of the following conditions will need the current directory.

View File

@ -185,10 +185,19 @@ TEST(Support, Path) {
path::native(*i, temp_store);
}
SmallString<32> Relative("foo.cpp");
sys::fs::make_absolute("/root", Relative);
Relative[5] = '/'; // Fix up windows paths.
ASSERT_EQ("/root/foo.cpp", Relative);
{
SmallString<32> Relative("foo.cpp");
sys::fs::make_absolute("/root", Relative);
Relative[5] = '/'; // Fix up windows paths.
ASSERT_EQ("/root/foo.cpp", Relative);
}
{
SmallString<32> Relative("foo.cpp");
sys::fs::make_absolute("//root", Relative);
Relative[6] = '/'; // Fix up windows paths.
ASSERT_EQ("//root/foo.cpp", Relative);
}
}
TEST(Support, FilenameParent) {