Skip to content

Commit cb6f264

Browse files
committed
[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
1 parent 4b03364 commit cb6f264

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

llvm/lib/Support/Path.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -855,11 +855,11 @@ void make_absolute(const Twine &current_directory,
855855
StringRef p(path.data(), path.size());
856856

857857
bool rootDirectory = path::has_root_directory(p);
858-
bool rootName =
859-
(real_style(Style::native) != Style::windows) || path::has_root_name(p);
858+
bool rootName = path::has_root_name(p);
860859

861860
// Already absolute.
862-
if (rootName && rootDirectory)
861+
if ((rootName || real_style(Style::native) != Style::windows) &&
862+
rootDirectory)
863863
return;
864864

865865
// All of the following conditions will need the current directory.

llvm/unittests/Support/Path.cpp

+13-4
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,19 @@ TEST(Support, Path) {
185185
path::native(*i, temp_store);
186186
}
187187

188-
SmallString<32> Relative("foo.cpp");
189-
sys::fs::make_absolute("/root", Relative);
190-
Relative[5] = '/'; // Fix up windows paths.
191-
ASSERT_EQ("/root/foo.cpp", Relative);
188+
{
189+
SmallString<32> Relative("foo.cpp");
190+
sys::fs::make_absolute("/root", Relative);
191+
Relative[5] = '/'; // Fix up windows paths.
192+
ASSERT_EQ("/root/foo.cpp", Relative);
193+
}
194+
195+
{
196+
SmallString<32> Relative("foo.cpp");
197+
sys::fs::make_absolute("//root", Relative);
198+
Relative[6] = '/'; // Fix up windows paths.
199+
ASSERT_EQ("//root/foo.cpp", Relative);
200+
}
192201
}
193202

194203
TEST(Support, FilenameParent) {

0 commit comments

Comments
 (0)