diff options
Diffstat (limited to 'clang/lib/Tooling/AllTUsExecution.cpp')
-rw-r--r-- | clang/lib/Tooling/AllTUsExecution.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/clang/lib/Tooling/AllTUsExecution.cpp b/clang/lib/Tooling/AllTUsExecution.cpp index b761556ee76..a7af541cc5d 100644 --- a/clang/lib/Tooling/AllTUsExecution.cpp +++ b/clang/lib/Tooling/AllTUsExecution.cpp @@ -104,7 +104,12 @@ llvm::Error AllTUsToolExecutor::execute( { llvm::ThreadPool Pool(ThreadCount == 0 ? llvm::hardware_concurrency() : ThreadCount); - + llvm::SmallString<128> InitialWorkingDir; + if (auto EC = llvm::sys::fs::current_path(InitialWorkingDir)) { + InitialWorkingDir = ""; + llvm::errs() << "Error while getting current working directory: " + << EC.message() << "\n"; + } for (std::string File : Files) { Pool.async( [&](std::string Path) { @@ -116,12 +121,19 @@ llvm::Error AllTUsToolExecutor::execute( for (const auto &FileAndContent : OverlayFiles) Tool.mapVirtualFile(FileAndContent.first(), FileAndContent.second); + // Do not restore working dir from multiple threads to avoid races. + Tool.setRestoreWorkingDir(false); if (Tool.run(Action.first.get())) AppendError(llvm::Twine("Failed to run action on ") + Path + "\n"); }, File); } + if (!InitialWorkingDir.empty()) { + if (auto EC = llvm::sys::fs::set_current_path(InitialWorkingDir)) + llvm::errs() << "Error while restoring working directory: " + << EC.message() << "\n"; + } } if (!ErrorMsg.empty()) |