[Lldb-commits] [PATCH] D46783: FileSpec objects that resolve to "." should have "." in m_filename and m_directory empty.

Greg Clayton via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri May 11 15:57:00 PDT 2018


clayborg created this revision.
clayborg added reviewers: labath, jingham, davide, zturner.

After switching to LLVM normalization, if we init FileSpec with "." we would end up with m_directory being NULL and m_filename being "".

This patch fixes this by allowing the path to be normalized and if it normalized to nothing, set it to m_filename.


https://reviews.llvm.org/D46783

Files:
  source/Utility/FileSpec.cpp
  unittests/Utility/FileSpecTest.cpp


Index: unittests/Utility/FileSpecTest.cpp
===================================================================
--- unittests/Utility/FileSpecTest.cpp
+++ unittests/Utility/FileSpecTest.cpp
@@ -201,9 +201,9 @@
       {"/..", "/"},
       {"/.", "/"},
       {"..", ".."},
-      {".", ""},
+      {".", "."},
       {"../..", "../.."},
-      {"foo/..", ""},
+      {"foo/..", "."},
       {"foo/../bar", "bar"},
       {"../foo/..", ".."},
       {"./foo", "foo"},
@@ -232,11 +232,11 @@
       {R"(\..)", R"(\..)"},
       //      {R"(c:..)", R"(c:..)"},
       {R"(..)", R"(..)"},
-      {R"(.)", R"()"},
+      {R"(.)", R"(.)"},
       // TODO: fix llvm::sys::path::remove_dots() to return "c:\" below.
       {R"(c:..\..)", R"(c:\..\..)"},
       {R"(..\..)", R"(..\..)"},
-      {R"(foo\..)", R"()"},
+      {R"(foo\..)", R"(.)"},
       {R"(foo\..\bar)", R"(bar)"},
       {R"(..\foo\..)", R"(..)"},
       {R"(.\foo)", R"(foo)"},
Index: source/Utility/FileSpec.cpp
===================================================================
--- source/Utility/FileSpec.cpp
+++ source/Utility/FileSpec.cpp
@@ -340,6 +340,13 @@
     std::replace(resolved.begin(), resolved.end(), '\\', '/');
 
   llvm::StringRef resolve_path_ref(resolved.c_str());
+  if (!pathname.empty() && resolve_path_ref.empty()) {
+    // We have a non empty specified that resulted in an empty normalized path
+    // so this resolved to the current working directory. Don't let m_directory
+    // or m_filename be empty.
+    m_filename.SetString(".");
+    return;
+  }
   size_t dir_end = ParentPathEnd(resolve_path_ref, m_syntax);
   if (dir_end == 0) {
     m_filename.SetString(resolve_path_ref);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46783.146434.patch
Type: text/x-patch
Size: 1674 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20180511/ac99fa06/attachment-0001.bin>


More information about the lldb-commits mailing list