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);


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);
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to