[clang-tools-extra] [clangd] Fix prerequisite module stale dependency detection (PR #234181)

Aleksandr Platonov via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 29 05:10:33 PDT 2026


================
@@ -1235,6 +1243,39 @@ void ModulesBuilder::ModulesBuilderImpl::getPrebuiltModuleFile(
   }
 }
 
+bool ModulesBuilder::ModulesBuilderImpl::hasNewerDependency(
+    StringRef ModuleName, PathRef PublishedModuleFilePath,
+    PathRef RequiredSource, PathRef ModuleUnitFileName,
+    CachingProjectModules &MDB) {
+  std::vector<std::string> Deps = MDB.getRequiredModules(ModuleUnitFileName);
+  if (Deps.empty())
+    return false;
+
+  llvm::sys::fs::file_status Status;
+  // Without a published module file there is nothing to compare against, so
+  // treat any cached copy as stale.
+  if (llvm::sys::fs::status(PublishedModuleFilePath, Status))
+    return true;
+  const auto ModuleTime = Status.getLastModificationTime();
+
+  return llvm::any_of(Deps, [&](const std::string &Dep) {
+    std::string DepSource = MDB.getSourceForModuleName(Dep, RequiredSource);
+    if (DepSource.empty())
+      return false;
+    auto DepCmd = getCDB().getCompileCommand(DepSource);
+    if (!DepCmd)
+      return false;
+    const std::string DepPublishedPath = getPublishedModuleFilePath(
+        Dep, getModuleFilesDirectory(DepSource, *DepCmd, getCDB()));
+    llvm::sys::fs::file_status DepStatus;
+    // Dependencies that clangd didn't publish, like module files from the
+    // build system, are validated by the AST reader instead.
+    if (llvm::sys::fs::status(DepPublishedPath, DepStatus))
----------------
ArcsinX wrote:

I think we should pass TFS here and use it, instead of `llvm::sys:fs:...`

https://github.com/llvm/llvm-project/pull/234181


More information about the cfe-commits mailing list