浏览代码

Fix issue sys::findProgramByName cannot find exe on path (#4960)

* Fix issue sys::findProgramByName cannot find exe on path
Merge https://github.com/llvm/llvm-project/commit/87780300f624e5437aee0c5a2d7ca30ea87b5ba2
to fix test issue where not.exe cannot find file.exe in
https://github.com/microsoft/DirectXShaderCompiler/blob/main/tools/clang/test/DXC/embed_dbg.test#L4
Xiang Li 2 年之前
父节点
当前提交
3949a2ba29
共有 1 个文件被更改,包括 9 次插入6 次删除
  1. 9 6
      lib/Support/Windows/Program.inc

+ 9 - 6
lib/Support/Windows/Program.inc

@@ -70,14 +70,17 @@ ErrorOr<std::string> sys::findProgramByName(StringRef Name,
   SmallVector<wchar_t, MAX_PATH> U16Result;
   DWORD Len = MAX_PATH;
   for (StringRef Ext : PathExts) {
-    SmallVector<wchar_t, MAX_PATH> U16Ext;
-    if (std::error_code EC = windows::UTF8ToUTF16(Ext, U16Ext))
-      return EC;
-
     do {
       U16Result.reserve(Len);
-      Len = ::SearchPathW(Path, c_str(U16Name),
-                          U16Ext.empty() ? nullptr : c_str(U16Ext),
+      // Lets attach the extension manually. That is needed for files
+      // with a point in name like aaa.bbb. SearchPathW will not add extension
+      // from its argument to such files because it thinks they already had one.
+      SmallVector<wchar_t, MAX_PATH> U16NameExt;
+      if (std::error_code EC =
+              windows::UTF8ToUTF16(Twine(Name + Ext).str(), U16NameExt))
+        return EC;
+
+      Len = ::SearchPathW(Path, c_str(U16NameExt), nullptr,
                           U16Result.capacity(), U16Result.data(), nullptr);
     } while (Len > U16Result.capacity());