[clang] [clang][deps] Value-compare buffers in the in-process module cache (PR #194888)

via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 29 08:37:17 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Jan Svoboda (jansvoboda11)

<details>
<summary>Changes</summary>

The `MemoryBufferRef::operator==()` function performs pointer comparison instead of value comparison. This means that the assertion in `InProcessModuleCache` always fires if there's a race between two producers of a PCM. This PR makes sure to value-compare the contained `StringRef` buffers.

---
Full diff: https://github.com/llvm/llvm-project/pull/194888.diff


1 Files Affected:

- (modified) clang/lib/DependencyScanning/InProcessModuleCache.cpp (+2-1) 


``````````diff
diff --git a/clang/lib/DependencyScanning/InProcessModuleCache.cpp b/clang/lib/DependencyScanning/InProcessModuleCache.cpp
index 0e2286c18e902..4ee8fe4fee1b9 100644
--- a/clang/lib/DependencyScanning/InProcessModuleCache.cpp
+++ b/clang/lib/DependencyScanning/InProcessModuleCache.cpp
@@ -145,7 +145,8 @@ class InProcessModuleCache : public ModuleCache {
     ModuleCacheEntry &Entry = getOrCreateEntry(Path);
     std::lock_guard<std::mutex> Lock(Entry.Mutex);
     if (Entry.State == ModuleCacheEntry::S_Written) {
-      assert(Entry.Buffer && *Entry.Buffer == Buffer &&
+      assert(Entry.Buffer && "Wrote PCM with no contents");
+      assert(Entry.Buffer->getBuffer() == Buffer->getBuffer() &&
              "Wrote the same PCM with different contents");
       Size = Entry.Buffer->getBufferSize();
       ModTime = Entry.ModTime;

``````````

</details>


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


More information about the cfe-commits mailing list