From: Jonas Devlieghere Date: Tue, 6 Aug 2019 15:46:45 +0000 (+0000) Subject: [Path] Fix bug in make_absolute logic X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=21adcf192d24a097c62938b9ec2d9c63ae321b68;p=llvm [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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368053 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp index c49260125db..14def83802d 100644 --- a/lib/Support/Path.cpp +++ b/lib/Support/Path.cpp @@ -855,11 +855,11 @@ void make_absolute(const Twine ¤t_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. diff --git a/unittests/Support/Path.cpp b/unittests/Support/Path.cpp index 5e0581c945b..1802b0031ad 100644 --- a/unittests/Support/Path.cpp +++ b/unittests/Support/Path.cpp @@ -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) {