Skip to content

Commit 76485a8

Browse files
committed
[clang][deps] Fix race condition
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 (cherry picked from commit 152f291)
1 parent 6be68b9 commit 76485a8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

clang/tools/clang-scan-deps/ClangScanDeps.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,15 +525,18 @@ class FullDeps {
525525
public:
526526
void mergeDeps(StringRef Input, TranslationUnitDeps TUDeps,
527527
size_t InputIndex) {
528+
mergeDeps(std::move(TUDeps.ModuleGraph), InputIndex);
529+
528530
InputDeps ID;
529531
ID.FileName = std::string(Input);
530532
ID.ContextHash = std::move(TUDeps.ID.ContextHash);
531533
ID.FileDeps = std::move(TUDeps.FileDeps);
532534
ID.ModuleDeps = std::move(TUDeps.ClangModuleDeps);
533535
ID.CASFileSystemRootID = TUDeps.CASFileSystemRootID;
534-
mergeDeps(std::move(TUDeps.ModuleGraph), InputIndex);
535536
ID.DriverCommandLine = std::move(TUDeps.DriverCommandLine);
536537
ID.Commands = std::move(TUDeps.Commands);
538+
539+
std::unique_lock<std::mutex> ul(Lock);
537540
Inputs.push_back(std::move(ID));
538541
}
539542

0 commit comments

Comments
 (0)