Skip to content

Commit 8d7f7d4

Browse files
committed
Propagate stat failures to shared cache by adding forgotten reference
1 parent a686c41 commit 8d7f7d4

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,12 @@ DependencyScanningFilesystemSharedCache::CacheShard::
130130
getOrEmplaceEntryForFilename(StringRef Filename,
131131
llvm::ErrorOr<llvm::vfs::Status> Stat) {
132132
std::lock_guard<std::mutex> LockGuard(CacheLock);
133-
const CachedFileSystemEntry *StoredEntry = CacheByFilename[Filename].first;
134-
if (!StoredEntry)
135-
StoredEntry =
133+
auto [It, Inserted] = CacheByFilename.insert({Filename, {nullptr, nullptr}});
134+
auto &[CachedEntry, CachedRealPath] = It->getValue();
135+
if (!CachedEntry)
136+
CachedEntry =
136137
new (EntryStorage.Allocate()) CachedFileSystemEntry(std::move(Stat));
137-
return *StoredEntry;
138+
return *CachedEntry;
138139
}
139140

140141
const CachedFileSystemEntry &

clang/unittests/Tooling/DependencyScanning/DependencyScanningFilesystemTest.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ using namespace clang::tooling::dependencies;
1616
namespace {
1717
struct InstrumentingFilesystem
1818
: llvm::RTTIExtends<InstrumentingFilesystem, llvm::vfs::ProxyFileSystem> {
19+
unsigned NumStatusCalls = 0;
1920
unsigned NumGetRealPathCalls = 0;
2021

2122
using llvm::RTTIExtends<InstrumentingFilesystem,
2223
llvm::vfs::ProxyFileSystem>::RTTIExtends;
2324

25+
llvm::ErrorOr<llvm::vfs::Status> status(const llvm::Twine &Path) override {
26+
++NumStatusCalls;
27+
return ProxyFileSystem::status(Path);
28+
}
29+
2430
std::error_code getRealPath(const llvm::Twine &Path,
2531
llvm::SmallVectorImpl<char> &Output) override {
2632
++NumGetRealPathCalls;
@@ -29,6 +35,29 @@ struct InstrumentingFilesystem
2935
};
3036
} // namespace
3137

38+
TEST(DependencyScanningWorkerFilesystem, CacheStatusFailures) {
39+
auto InMemoryFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>();
40+
41+
auto InstrumentingFS =
42+
llvm::makeIntrusiveRefCnt<InstrumentingFilesystem>(InMemoryFS);
43+
44+
DependencyScanningFilesystemSharedCache SharedCache;
45+
DependencyScanningWorkerFilesystem DepFS(SharedCache, InstrumentingFS);
46+
DependencyScanningWorkerFilesystem DepFS2(SharedCache, InstrumentingFS);
47+
48+
DepFS.status("/foo.c");
49+
EXPECT_EQ(InstrumentingFS->NumStatusCalls, 1u);
50+
51+
DepFS.status("/foo.c");
52+
EXPECT_EQ(InstrumentingFS->NumStatusCalls, 1u); // Cached, no increase.
53+
54+
DepFS.status("/bar.c");
55+
EXPECT_EQ(InstrumentingFS->NumStatusCalls, 2u);
56+
57+
DepFS2.status("/foo.c");
58+
EXPECT_EQ(InstrumentingFS->NumStatusCalls, 2u); // Shared cache.
59+
}
60+
3261
TEST(DependencyScanningFilesystem, CacheGetRealPath) {
3362
auto InMemoryFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>();
3463
InMemoryFS->setCurrentWorkingDirectory("/");

0 commit comments

Comments
 (0)