Skip to content

Commit

Permalink
[clang][deps] Fix race condition
Browse files Browse the repository at this point in the history
D140176 introduced new `FullDeps` API that's not thread-safe, breaking the class invariant. This was causing race condition when `clang-scan-deps` was run with multiple threads.

Reviewed By: steven_wu, akyrtzi

Differential Revision: https://reviews.llvm.org/D143428
  • Loading branch information
jansvoboda11 committed Feb 7, 2023
1 parent 140bc41 commit 152f291
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion clang/tools/clang-scan-deps/ClangScanDeps.cpp
Expand Up @@ -252,14 +252,17 @@ class FullDeps {
public:
void mergeDeps(StringRef Input, TranslationUnitDeps TUDeps,
size_t InputIndex) {
mergeDeps(std::move(TUDeps.ModuleGraph), InputIndex);

InputDeps ID;
ID.FileName = std::string(Input);
ID.ContextHash = std::move(TUDeps.ID.ContextHash);
ID.FileDeps = std::move(TUDeps.FileDeps);
ID.ModuleDeps = std::move(TUDeps.ClangModuleDeps);
mergeDeps(std::move(TUDeps.ModuleGraph), InputIndex);
ID.DriverCommandLine = std::move(TUDeps.DriverCommandLine);
ID.Commands = std::move(TUDeps.Commands);

std::unique_lock<std::mutex> ul(Lock);
Inputs.push_back(std::move(ID));
}

Expand Down

0 comments on commit 152f291

Please sign in to comment.