kousikk updated this revision to Diff 219891. kousikk added a comment. - Add validation inside the createFile() function
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D67091/new/ https://reviews.llvm.org/D67091 Files: clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp Index: clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp =================================================================== --- clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp +++ clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp @@ -176,6 +176,8 @@ llvm::ErrorOr<StringRef> Contents = Entry->getContents(); if (!Contents) return Contents.getError(); + if (Entry->isDirectory()) + return llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>(std::make_error_code(std::errc::is_a_directory)); return std::make_unique<MinimizedVFSFile>( llvm::MemoryBuffer::getMemBuffer(*Contents, Entry->getName(), /*RequiresNullTerminator=*/false), Index: clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h =================================================================== --- clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h +++ 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<StringRef> getContents() const { if (!MaybeStat)
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp =================================================================== --- clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp +++ clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp @@ -176,6 +176,8 @@ llvm::ErrorOr<StringRef> Contents = Entry->getContents(); if (!Contents) return Contents.getError(); + if (Entry->isDirectory()) + return llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>(std::make_error_code(std::errc::is_a_directory)); return std::make_unique<MinimizedVFSFile>( llvm::MemoryBuffer::getMemBuffer(*Contents, Entry->getName(), /*RequiresNullTerminator=*/false), Index: clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h =================================================================== --- clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h +++ 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<StringRef> getContents() const { if (!MaybeStat)
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits