Skip to content

Commit 1f2d65f

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 8b9897e commit 1f2d65f

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
@@ -1669,6 +1669,14 @@ static bool compileModuleAndReadASTImpl(CompilerInstance &ImportingInstance,
16691669
}
16701670
}
16711671

1672+
// The module is built successfully, we can update its timestamp now.
1673+
if (ImportingInstance.getPreprocessor()
1674+
.getHeaderSearchInfo()
1675+
.getHeaderSearchOpts()
1676+
.ModulesValidateOncePerBuildSession) {
1677+
ImportingInstance.getModuleCache().updateModuleTimestamp(ModuleFileName);
1678+
}
1679+
16721680
return readASTAfterCompileModule(ImportingInstance, ImportLoc, ModuleNameLoc,
16731681
Module, ModuleFileName,
16741682
/*OutOfDate=*/nullptr, /*Missing=*/nullptr);

clang/lib/Serialization/ASTWriter.cpp

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

55485548
WritingAST = false;
55495549

5550-
if (WritingModule && PPRef.getHeaderSearchInfo()
5551-
.getHeaderSearchOpts()
5552-
.ModulesValidateOncePerBuildSession)
5553-
ModCache.updateModuleTimestamp(OutputFile);
5554-
55555550
if (ShouldCacheASTInMemory) {
55565551
// Construct MemoryBuffer and update buffer manager.
55575552
ModCache.getInMemoryModuleCache().addBuiltPCM(

0 commit comments

Comments
 (0)