summaryrefslogtreecommitdiffstats
path: root/clang/lib/Tooling/AllTUsExecution.cpp
diff options
context:
space:
mode:
authorIlya Biryukov <ibiryukov@google.com>2018-09-11 07:29:09 +0000
committerIlya Biryukov <ibiryukov@google.com>2018-09-11 07:29:09 +0000
commit008eda080786e110914f4aa57d31342098046c94 (patch)
tree88ce3b59ebf9370d944bef13834607019c032f2c /clang/lib/Tooling/AllTUsExecution.cpp
parentec605d38461795c9e916cf536a0b2048ede86c1a (diff)
downloadbcm5719-llvm-008eda080786e110914f4aa57d31342098046c94.tar.gz
bcm5719-llvm-008eda080786e110914f4aa57d31342098046c94.zip
[Tooling] Restore working dir in ClangTool.
Summary: And add an option to disable this behavior. The option is only used in AllTUsExecutor to avoid races when running concurrently on multiple threads. This fixes PR38869 introduced by r340937. Reviewers: ioeric, steveire Reviewed By: ioeric Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D51864 llvm-svn: 341910
Diffstat (limited to 'clang/lib/Tooling/AllTUsExecution.cpp')
-rw-r--r--clang/lib/Tooling/AllTUsExecution.cpp14
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())
OpenPOWER on IntegriCloud