[PATCH] D49451: [windows] Use a well-known path for ComSpec if we fail to retrieve it

Stella Stamenova via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 17 13:29:25 PDT 2018


stella.stamenova created this revision.
stella.stamenova added reviewers: asmith, zturner, labath.
Herald added a subscriber: llvm-commits.

Right now we always try to retrieve ComSpec and if we fail, we give up. This rarely fails, but we can update the logic so that we fail even less frequently. Since there is a well-known path (albeit not always correct), try the path when we failed to retrieve it. Note that on other platforms, we generally just return a well-known path without any checking.


Repository:
  rL LLVM

https://reviews.llvm.org/D49451

Files:
  source/Host/windows/HostInfoWindows.cpp


Index: source/Host/windows/HostInfoWindows.cpp
===================================================================
--- source/Host/windows/HostInfoWindows.cpp
+++ source/Host/windows/HostInfoWindows.cpp
@@ -98,9 +98,14 @@
 }
 
 FileSpec HostInfoWindows::GetDefaultShell() {
+  // Try to retrieve ComSpec from the environment. On the rare occasion
+  // that it fails, try a well-known path for ComSpec instead.
+
   std::string shell;
-  GetEnvironmentVar("ComSpec", shell);
-  return FileSpec(shell, false);
+  if (GetEnvironmentVar("ComSpec", shell))
+    return FileSpec(shell, false);
+
+  return FileSpec("C:\\Windows\\system32\\cmd.exe", false);
 }
 
 bool HostInfoWindows::GetEnvironmentVar(const std::string &var_name,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49451.155957.patch
Type: text/x-patch
Size: 727 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180717/73e36129/attachment.bin>


More information about the llvm-commits mailing list