[clang] [clang] Use the module cache's view of built PCMs (PR #242383)
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 13 17:12:40 PST 2026
================
@@ -74,3 +75,42 @@ TEST(InProcessModuleCache, ReadReadInvalidation) {
EXPECT_EQ(Buf1->getBuffer().begin(), Buf2->getBuffer().begin());
EXPECT_EQ(Buf1->getBuffer().end(), Buf2->getBuffer().end());
}
+
+TEST(InProcessModuleCache, WriteReturnsSharedBuffer) {
+ ModuleCacheEntries Entries;
+ AtomicLineLogger Logger;
+ std::shared_ptr<ModuleCache> ModCache =
+ makeInProcessModuleCache(Entries, Logger);
+
+ llvm::SmallString<256> Path;
+ llvm::sys::fs::createUniquePath("M-%%%%%%.pcm", Path, /*MakeAbsolute=*/true);
+
+ off_t Size;
+ time_t ModTime;
+ std::unique_ptr<llvm::MemoryBuffer> Written;
+ {
+ std::string Contents = "contents\n";
+ auto WrittenOrErr = ModCache->write(
+ Path, llvm::MemoryBuffer::getMemBufferCopy(Contents, Path), Size,
+ ModTime);
+ ASSERT_EQ(WrittenOrErr.getError(), std::error_code{});
+ Written = std::move(*WrittenOrErr);
+ }
+ // The returned buffer doesn't reference the written contents.
----------------
jansvoboda11 wrote:
Reworded the comment and expectations to make it clear that we're checking the reuse of the buffer written first (instead of making copies).
https://github.com/llvm/llvm-project/pull/242383
More information about the cfe-commits
mailing list