llvm::sys::path::home_directory() relies on having "HOME" set in the environment and that might not always be set. Our FileSpec class uses this function to resolve any paths that start with "~/" on systems that support home directories as '~'. I have modified FileSpec::ResolveUsername (llvm::SmallVectorImpl<char> &path) to deal with the cases where llvm::sys::path::home_directory() returns false by digging a little further on unix systems and setting "HOME" in the environment so that subsequent calls to llvm::sys::path::home_directory() will succeed.

I also added a test to ensure we don't regress.

<rdar://problem/25342377> 

llvm-svn: 266832
diff --git a/lldb/source/Host/common/FileSpec.cpp b/lldb/source/Host/common/FileSpec.cpp
index 074ec83..53c0ab4 100644
--- a/lldb/source/Host/common/FileSpec.cpp
+++ b/lldb/source/Host/common/FileSpec.cpp
@@ -185,8 +185,22 @@
     {
         // A path of ~/ resolves to the current user's home dir
         llvm::SmallString<64> home_dir;
+        // llvm::sys::path::home_directory() only checks if "HOME" is set in the
+        // environment and does nothing else to locate the user home directory
         if (!llvm::sys::path::home_directory(home_dir))
-            return;
+        {
+            struct passwd *pw = getpwuid(getuid());
+            if (pw && pw->pw_dir && pw->pw_dir[0])
+            {
+                // Update our environemnt so llvm::sys::path::home_directory() works next time
+                setenv("HOME", pw->pw_dir, 0);
+                home_dir.assign(llvm::StringRef(pw->pw_dir));
+            }
+            else
+            {
+                return;
+            }
+        }
         
         // Overwrite the ~ with the first character of the homedir, and insert
         // the rest.  This way we only trigger one move, whereas an insert