[llvm] [llvm][Support][Windows] Avoid crash calling remove_directories() (PR #118677)

Dmitry Vasilyev via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 11 15:46:29 PST 2024


================
@@ -1387,14 +1388,33 @@ std::error_code remove_directories(const Twine &path, bool IgnoreErrors) {
   Path16.push_back(0);
   Path16.push_back(0);
 
-  SHFILEOPSTRUCTW shfos = {};
-  shfos.wFunc = FO_DELETE;
-  shfos.pFrom = Path16.data();
-  shfos.fFlags = FOF_NO_UI;
-
-  int result = ::SHFileOperationW(&shfos);
-  if (result != 0 && !IgnoreErrors)
-    return mapWindowsError(result);
+  HRESULT HR;
+  do {
+    HR =
+        CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
----------------
slydiman wrote:

https://github.com/llvm/llvm-project/pull/118677#issuecomment-2525650510

> Please note my second commit is the result of disassembling SHFileOperationW(). I have figured out the parameters for CoInitializeEx() and used ILCreateFromPathW() and SHCreateItemFromIDList() instead of SHCreateItemFromParsingName(). So SHFileOperationW() does it anyway.

https://github.com/llvm/llvm-project/pull/118677


More information about the llvm-commits mailing list