[llvm] r368053 - [Path] Fix bug in make_absolute logic

Jonas Devlieghere via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 6 08:46:46 PDT 2019


Author: jdevlieghere
Date: Tue Aug  6 08:46:45 2019
New Revision: 368053

URL: http://llvm.org/viewvc/llvm-project?rev=368053&view=rev
Log:
[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

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=368053&r1=368052&r2=368053&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Path.cpp (original)
+++ llvm/trunk/lib/Support/Path.cpp Tue Aug  6 08:46:45 2019
@@ -855,11 +855,11 @@ void make_absolute(const Twine &current_
   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.

Modified: llvm/trunk/unittests/Support/Path.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/Path.cpp?rev=368053&r1=368052&r2=368053&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/Path.cpp (original)
+++ llvm/trunk/unittests/Support/Path.cpp Tue Aug  6 08:46:45 2019
@@ -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) {




More information about the llvm-commits mailing list