From 5abcc242a65b4968cfbd706705c611b691f196ab Mon Sep 17 00:00:00 2001 From: Qiongsi Wu Date: Fri, 1 Aug 2025 14:03:25 -0700 Subject: [PATCH] Move the code to update timestamp later to avoid updating timestamp before the pcm is committed to disk. --- clang/lib/Frontend/CompilerInstance.cpp | 8 ++++++++ clang/lib/Serialization/ASTWriter.cpp | 5 ----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index ed6a651d919a1..ae285b117f5e0 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -1480,6 +1480,14 @@ static bool compileModuleAndReadASTImpl(CompilerInstance &ImportingInstance, return false; } + // The module is built successfully, we can update its timestamp now. + if (ImportingInstance.getPreprocessor() + .getHeaderSearchInfo() + .getHeaderSearchOpts() + .ModulesValidateOncePerBuildSession) { + ImportingInstance.getModuleCache().updateModuleTimestamp(ModuleFileName); + } + return readASTAfterCompileModule(ImportingInstance, ImportLoc, ModuleNameLoc, Module, ModuleFileName, /*OutOfDate=*/nullptr, /*Missing=*/nullptr); diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index a6957e54b66f1..0c7ddd07553a4 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -5461,11 +5461,6 @@ ASTWriter::WriteAST(llvm::PointerUnion Subject, WritingAST = false; - if (WritingModule && PPRef.getHeaderSearchInfo() - .getHeaderSearchOpts() - .ModulesValidateOncePerBuildSession) - ModCache.updateModuleTimestamp(OutputFile); - if (ShouldCacheASTInMemory) { // Construct MemoryBuffer and update buffer manager. ModCache.getInMemoryModuleCache().addBuiltPCM(