[clang] [clang][Dependency Scanning] Adding an API to Diagnose Invalid Negative Stat Cache Entries (PR #135703)
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 17 16:07:27 PDT 2025
================
@@ -108,6 +108,32 @@ DependencyScanningFilesystemSharedCache::getShardForUID(
return CacheShards[Hash % NumShards];
}
+void DependencyScanningFilesystemSharedCache::
+ diagnoseInvalidNegativeStatCachedPaths(
+ std::vector<std::string> &InvalidPaths,
+ llvm::vfs::FileSystem &UnderlyingFS) const {
+ // Iterate through all shards and look for cached stat errors.
+ for (unsigned i = 0; i < NumShards; i++) {
+ const CacheShard &Shard = CacheShards[i];
+ std::lock_guard<std::mutex> LockGuard(Shard.CacheLock);
+ for (const auto &[Path, CachedPair] : Shard.CacheByFilename) {
+ const CachedFileSystemEntry *Entry = CachedPair.first;
+
+ if (Entry->getError()) {
+ // Only examine cached errors.
+ llvm::ErrorOr<llvm::vfs::Status> Stat = UnderlyingFS.status(Path);
+ if (Stat) {
+ // This is the case where we have cached the non-existence
+ // of the file at Path first, and a a file at the path is created
+ // later. The cache entry is not invalidated (as we have no good
+ // way to do it now), which may lead to missing file build errors.
+ InvalidPaths.push_back(std::string(Path));
----------------
jansvoboda11 wrote:
Yeah, in general, we prefer reduce the number of allocations where we can for better performance.
https://github.com/llvm/llvm-project/pull/135703
More information about the cfe-commits
mailing list