[llvm] [llvm][Support][Windows] Avoid crash calling remove_directories() (PR #118677)
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 11 14:59:43 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);
----------------
rnk wrote:
Is anyone sure it is safe to do COM initialization deep in library code? See the docs and some comments in Chromium source code:
https://learn.microsoft.com/en-us/windows/win32/learnwin32/initializing-the-com-library
https://source.chromium.org/chromium/chromium/src/+/main:base/win/scoped_com_initializer.h;l=27;drc=0e516eb08aa56163bfe649cebbba13da1fcf5f3c
COM initialization seems to affect thread-wide state, so I would ideally prefer to find a way to avoid this.
OTOH, if you look across LLVM, there are only a few non-unittest uses of remove_directories, so maybe this is fine:
https://github.com/search?q=repo%3Allvm%2Fllvm-project%20remove_directories&type=code
https://github.com/llvm/llvm-project/pull/118677
More information about the llvm-commits
mailing list