[clang] [clang][deps] Value-compare buffers in the in-process module cache (PR #194888)
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 29 08:36:30 PDT 2026
https://github.com/jansvoboda11 created https://github.com/llvm/llvm-project/pull/194888
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.
>From ee210543b7be05fca5717510722a90a05f24a53d Mon Sep 17 00:00:00 2001
From: Jan Svoboda <jan_svoboda at apple.com>
Date: Wed, 29 Apr 2026 08:34:33 -0700
Subject: [PATCH] [clang][deps] Value-compare buffers in the in-process module
cache
---
clang/lib/DependencyScanning/InProcessModuleCache.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
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;
More information about the cfe-commits
mailing list