Skip to content

Commit 152f291

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
1 parent 140bc41 commit 152f291

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
@@ -252,14 +252,17 @@ class FullDeps {
252252
public:
253253
void mergeDeps(StringRef Input, TranslationUnitDeps TUDeps,
254254
size_t InputIndex) {
255+
mergeDeps(std::move(TUDeps.ModuleGraph), InputIndex);
256+
255257
InputDeps ID;
256258
ID.FileName = std::string(Input);
257259
ID.ContextHash = std::move(TUDeps.ID.ContextHash);
258260
ID.FileDeps = std::move(TUDeps.FileDeps);
259261
ID.ModuleDeps = std::move(TUDeps.ClangModuleDeps);
260-
mergeDeps(std::move(TUDeps.ModuleGraph), InputIndex);
261262
ID.DriverCommandLine = std::move(TUDeps.DriverCommandLine);
262263
ID.Commands = std::move(TUDeps.Commands);
264+
265+
std::unique_lock<std::mutex> ul(Lock);
263266
Inputs.push_back(std::move(ID));
264267
}
265268

0 commit comments

Comments
 (0)