https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/177383

Backport ada79f4

Requested by: @jansvoboda11

>From 295c0277570610f7ad34b5b16b7ab698ded57854 Mon Sep 17 00:00:00 2001
From: Jan Svoboda <[email protected]>
Date: Thu, 22 Jan 2026 07:15:26 -0800
Subject: [PATCH] [clang][modules] Read PCM validation timestamp earlier
 (#177062)

When building a module, the PCM file is always written first and then
the validation timestamp gets created. Clang needs to first read the
validation timestamp and only then read the PCM file. Otherwise, it
could read an out-of-date PCM file and then read the validation
timestamp for its new up-to-date version. This would erroneously skip
validation with `-fmodules-validate-once-per-build-session`. I'm not
concerned about multiple Clang instances seeing different filesystem
contents from each other within a single build session, since that would
break the assumption `-fmodules-validate-once-per-build-session` relies
on.

(cherry picked from commit ada79f4c2691ab6546d379a144377162fd4f5191)
---
 clang/lib/Serialization/ModuleManager.cpp | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Serialization/ModuleManager.cpp 
b/clang/lib/Serialization/ModuleManager.cpp
index 236fe20fdad7c..dad6840947ece 100644
--- a/clang/lib/Serialization/ModuleManager.cpp
+++ b/clang/lib/Serialization/ModuleManager.cpp
@@ -105,6 +105,10 @@ ModuleManager::addModule(StringRef FileName, ModuleKind 
Type,
                          std::string &ErrorStr) {
   Module = nullptr;
 
+  uint64_t InputFilesValidationTimestamp = 0;
+  if (Type == MK_ImplicitModule)
+    InputFilesValidationTimestamp = ModCache.getModuleTimestamp(FileName);
+
   // Look for the file entry. This only fails if the expected size or
   // modification time differ.
   OptionalFileEntryRef Entry;
@@ -172,11 +176,7 @@ ModuleManager::addModule(StringRef FileName, ModuleKind 
Type,
   NewModule->Index = Chain.size();
   NewModule->FileName = FileName.str();
   NewModule->ImportLoc = ImportLoc;
-  NewModule->InputFilesValidationTimestamp = 0;
-
-  if (NewModule->Kind == MK_ImplicitModule)
-    NewModule->InputFilesValidationTimestamp =
-        ModCache.getModuleTimestamp(NewModule->FileName);
+  NewModule->InputFilesValidationTimestamp = InputFilesValidationTimestamp;
 
   // Load the contents of the module
   if (std::unique_ptr<llvm::MemoryBuffer> Buffer = lookupBuffer(FileName)) {

_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to