diff --git a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h --- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h +++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h @@ -55,6 +55,11 @@ /// \returns True if the entry is valid. bool isValid() const { return !MaybeStat || MaybeStat->isStatusKnown(); } + /// \returns True if the current entry points to a directory. + bool isDirectory() const { + return MaybeStat && MaybeStat->isDirectory(); + } + /// \returns The error or the file's contents. llvm::ErrorOr getContents() const { if (!MaybeStat) diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp +++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp @@ -190,8 +190,11 @@ StringRef Filename = Path.toStringRef(OwnedFilename); // Check the local cache first. - if (const CachedFileSystemEntry *Entry = getCachedEntry(Filename)) - return createFile(Entry); + if (const CachedFileSystemEntry *Entry = getCachedEntry(Filename)) { + if (Entry->isDirectory()) { + return llvm::ErrorOr>(std::make_error_code(std::errc::is_a_directory)); + } + } // FIXME: Handle PCM/PCH files. // FIXME: Handle module map files.