Skip to content

Commit bfee42c

Browse files
qiongsiwucyndyishida
authored andcommitted
[clang][Dependency Scanning] Move Module Timestamp Update After Compilation Finishes (llvm#151774)
When two threads are accessing the same `pcm`, it is possible that the reading thread sees the timestamp update, while the file on disk is not updated. This PR moves timestamp update from `writeAST` to `compileModuleAndReadASTImpl`, so we only update the timestamp after the file has been committed to disk. rdar://152097193 (cherry picked from commit 09dbdf6)
1 parent 9784760 commit bfee42c

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,6 +1617,14 @@ static bool compileModuleAndReadASTImpl(CompilerInstance &ImportingInstance,
16171617
return false;
16181618
}
16191619

1620+
// The module is built successfully, we can update its timestamp now.
1621+
if (ImportingInstance.getPreprocessor()
1622+
.getHeaderSearchInfo()
1623+
.getHeaderSearchOpts()
1624+
.ModulesValidateOncePerBuildSession) {
1625+
ImportingInstance.getModuleCache().updateModuleTimestamp(ModuleFileName);
1626+
}
1627+
16201628
return readASTAfterCompileModule(ImportingInstance, ImportLoc, ModuleNameLoc,
16211629
Module, ModuleFileName,
16221630
/*OutOfDate=*/nullptr, /*Missing=*/nullptr);

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5031,11 +5031,6 @@ ASTWriter::WriteAST(llvm::PointerUnion<Sema *, Preprocessor *> Subject,
50315031

50325032
WritingAST = false;
50335033

5034-
if (WritingModule && PPRef.getHeaderSearchInfo()
5035-
.getHeaderSearchOpts()
5036-
.ModulesValidateOncePerBuildSession)
5037-
ModCache.updateModuleTimestamp(OutputFile);
5038-
50395034
if (ShouldCacheASTInMemory) {
50405035
// Construct MemoryBuffer and update buffer manager.
50415036
ModCache.getInMemoryModuleCache().addBuiltPCM(

0 commit comments

Comments
 (0)