https://github.com/jansvoboda11 updated 
https://github.com/llvm/llvm-project/pull/179510

>From 11c310a488c75e2ce07a0f448c90246268cdd588 Mon Sep 17 00:00:00 2001
From: Jan Svoboda <[email protected]>
Date: Tue, 3 Feb 2026 09:46:03 -0800
Subject: [PATCH 1/2] [clang][modules] Allow specifying thread-safe module
 cache

---
 clang/include/clang/Frontend/CompilerInstance.h |  7 +++++--
 clang/lib/Frontend/CompilerInstance.cpp         | 14 +++++++++-----
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/Frontend/CompilerInstance.h 
b/clang/include/clang/Frontend/CompilerInstance.h
index a3a4c7e55b72b..16442e2d5075d 100644
--- a/clang/include/clang/Frontend/CompilerInstance.h
+++ b/clang/include/clang/Frontend/CompilerInstance.h
@@ -872,20 +872,23 @@ class CompilerInstance : public ModuleLoader {
   class ThreadSafeCloneConfig {
     IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS;
     DiagnosticConsumer &DiagConsumer;
+    std::shared_ptr<ModuleCache> ModCache;
     std::shared_ptr<ModuleDependencyCollector> ModuleDepCollector;
 
   public:
     ThreadSafeCloneConfig(
         IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
-        DiagnosticConsumer &DiagConsumer,
+        DiagnosticConsumer &DiagConsumer, std::shared_ptr<ModuleCache> 
ModCache,
         std::shared_ptr<ModuleDependencyCollector> ModuleDepCollector = 
nullptr)
-        : VFS(std::move(VFS)), DiagConsumer(DiagConsumer),
+        : VFS(std::move(VFS)), DiagConsumer(DiagConsumer), ModCache(ModCache),
           ModuleDepCollector(std::move(ModuleDepCollector)) {
       assert(this->VFS && "Clone config requires non-null VFS");
+      assert(this->ModCache && "Clone config requires non-null ModuleCache");
     }
 
     IntrusiveRefCntPtr<llvm::vfs::FileSystem> getVFS() const { return VFS; }
     DiagnosticConsumer &getDiagConsumer() const { return DiagConsumer; }
+    std::shared_ptr<ModuleCache> getModuleCache() const { return ModCache; }
     std::shared_ptr<ModuleDependencyCollector> getModuleDepCollector() const {
       return ModuleDepCollector;
     }
diff --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index ae17e5467c712..ec4e80832b963 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -1167,12 +1167,16 @@ std::unique_ptr<CompilerInstance> 
CompilerInstance::cloneForModuleCompileImpl(
              Invocation->computeContextHash() &&
          "Module hash mismatch!");
 
-  // Construct a compiler instance that will be used to actually create the
-  // module.  Since we're sharing an in-memory module cache,
-  // CompilerInstance::CompilerInstance is responsible for finalizing the
-  // buffers to prevent use-after-frees.
+  std::shared_ptr<ModuleCache> ModCache;
+  if (ThreadSafeConfig) {
+    ModCache = ThreadSafeConfig->getModuleCache();
+  } else {
+    ModCache = this->ModCache;
+  }
+
+  // Construct a compiler instance that will be used to create the module.
   auto InstancePtr = std::make_unique<CompilerInstance>(
-      std::move(Invocation), getPCHContainerOperations(), ModCache);
+      std::move(Invocation), getPCHContainerOperations(), std::move(ModCache));
   auto &Instance = *InstancePtr;
 
   auto &Inv = Instance.getInvocation();

>From c40a6b9aa9e6bf15d5b0d3c0a8e73be9342864ca Mon Sep 17 00:00:00 2001
From: Jan Svoboda <[email protected]>
Date: Tue, 3 Feb 2026 19:46:57 -0800
Subject: [PATCH 2/2] Use `std::move`

---
 clang/include/clang/Frontend/CompilerInstance.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Frontend/CompilerInstance.h 
b/clang/include/clang/Frontend/CompilerInstance.h
index 16442e2d5075d..217efa3fe756e 100644
--- a/clang/include/clang/Frontend/CompilerInstance.h
+++ b/clang/include/clang/Frontend/CompilerInstance.h
@@ -880,7 +880,8 @@ class CompilerInstance : public ModuleLoader {
         IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
         DiagnosticConsumer &DiagConsumer, std::shared_ptr<ModuleCache> 
ModCache,
         std::shared_ptr<ModuleDependencyCollector> ModuleDepCollector = 
nullptr)
-        : VFS(std::move(VFS)), DiagConsumer(DiagConsumer), ModCache(ModCache),
+        : VFS(std::move(VFS)), DiagConsumer(DiagConsumer),
+          ModCache(std::move(ModCache)),
           ModuleDepCollector(std::move(ModuleDepCollector)) {
       assert(this->VFS && "Clone config requires non-null VFS");
       assert(this->ModCache && "Clone config requires non-null ModuleCache");

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

Reply via email to