[clang] [libclang] Add clang_ModuleCache_prune (PR #190067)

Cyndy Ishida via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 1 20:29:26 PDT 2026


================
@@ -60,38 +59,45 @@ void clang::maybePruneImpl(StringRef Path, time_t PruneInterval,
   // Walk the entire module cache, looking for unused module files and module
   // indices.
   std::error_code EC;
+  auto TryPruneFile = [&](StringRef FilePath) {
+    // We only care about module and global module index files.
+    StringRef Extension = llvm::sys::path::extension(FilePath);
+    if (Extension != ".pcm" && Extension != ".timestamp" &&
+        llvm::sys::path::filename(FilePath) != "modules.idx")
+      return;
+
+    // Look at this file. If we can't stat it, there's nothing interesting
+    // there.
+    if (llvm::sys::fs::status(FilePath, StatBuf))
+      return;
+
+    // If the file has been used recently enough, leave it there.
+    time_t FileAccessTime = llvm::sys::toTimeT(StatBuf.getLastAccessedTime());
+    if (CurrentTime - FileAccessTime <= PruneAfter)
+      return;
+
+    // Remove the file.
+    llvm::sys::fs::remove(FilePath);
+
+    // Remove the timestamp file.
+    std::string TimpestampFilename = FilePath.str() + ".timestamp";
----------------
cyndyishida wrote:

This is for the implicit modules compilation case right? I think that's worth mentioning as a comment. 

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


More information about the cfe-commits mailing list