Skip to content

Commit 0cb5017

Browse files
committed
[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 a3dbdfb commit 0cb5017

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
@@ -1626,6 +1626,14 @@ static bool compileModuleAndReadASTImpl(CompilerInstance &ImportingInstance,
16261626
return false;
16271627
}
16281628

1629+
// The module is built successfully, we can update its timestamp now.
1630+
if (ImportingInstance.getPreprocessor()
1631+
.getHeaderSearchInfo()
1632+
.getHeaderSearchOpts()
1633+
.ModulesValidateOncePerBuildSession) {
1634+
ImportingInstance.getModuleCache().updateModuleTimestamp(ModuleFileName);
1635+
}
1636+
16291637
return readASTAfterCompileModule(ImportingInstance, ImportLoc, ModuleNameLoc,
16301638
Module, ModuleFileName,
16311639
/*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)