]> granicus.if.org Git - llvm/commitdiff
[Path] Fix bug in make_absolute logic
authorJonas Devlieghere <jonas@devlieghere.com>
Tue, 6 Aug 2019 15:46:45 +0000 (15:46 +0000)
committerJonas Devlieghere <jonas@devlieghere.com>
Tue, 6 Aug 2019 15:46:45 +0000 (15:46 +0000)
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

lib/Support/Path.cpp
unittests/Support/Path.cpp

index c49260125dba629a00a59434be512ae53a571221..14def83802dafea3307b62bfdf0be009dc1651ac 100644 (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.
index 5e0581c945b0c6a20cb2838b9d36973e8cd12f63..1802b0031ad7bcaf00de4bb24f49f064b90a3a27 100644 (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) {