github.com/distbuild/reclient@v0.0.0-20240401075343-3de72e395564/third_party/patches/llvm/llvm-status-is-for-dir.patch (about)

     1  diff --git a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
     2  index af02fa2e7e87..5cdc80a69cbc 100644
     3  --- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
     4  +++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h
     5  @@ -191,7 +191,7 @@ public:
     6         : ProxyFileSystem(std::move(FS)), SharedCache(SharedCache),
     7           PPSkipMappings(PPSkipMappings) {}
     8   
     9  -  llvm::ErrorOr<llvm::vfs::Status> status(const Twine &Path) override;
    10  +  llvm::ErrorOr<llvm::vfs::Status> status(const Twine &Path, bool isForDir = false) override;
    11     llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>
    12     openFileForRead(const Twine &Path) override;
    13   
    14  @@ -205,7 +205,7 @@ private:
    15     bool shouldMinimize(StringRef Filename);
    16   
    17     llvm::ErrorOr<const CachedFileSystemEntry *>
    18  -  getOrCreateFileSystemEntry(const StringRef Filename);
    19  +  getOrCreateFileSystemEntry(const StringRef Filename, bool isForDir = false);
    20   
    21     /// Create a cached file system entry based on the initial status result.
    22     CachedFileSystemEntry
    23  diff --git a/clang/lib/Basic/FileSystemStatCache.cpp b/clang/lib/Basic/FileSystemStatCache.cpp
    24  index 415a4e2025df..416e3f26dd15 100644
    25  --- a/clang/lib/Basic/FileSystemStatCache.cpp
    26  +++ b/clang/lib/Basic/FileSystemStatCache.cpp
    27  @@ -44,7 +44,7 @@ FileSystemStatCache::get(StringRef Path, llvm::vfs::Status &Status,
    28     else if (isForDir || !F) {
    29       // If this is a directory or a file descriptor is not needed and we have
    30       // no cache, just go to the file system.
    31  -    llvm::ErrorOr<llvm::vfs::Status> StatusOrErr = FS.status(Path);
    32  +    llvm::ErrorOr<llvm::vfs::Status> StatusOrErr = FS.status(Path, isForDir);
    33       if (!StatusOrErr) {
    34         RetCode = StatusOrErr.getError();
    35       } else {
    36  diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
    37  index f7c711690d7e..82bd4c380cfe 100644
    38  --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
    39  +++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
    40  @@ -182,7 +182,7 @@ CachedFileSystemEntry DependencyScanningWorkerFilesystem::createFileSystemEntry(
    41   
    42   llvm::ErrorOr<const CachedFileSystemEntry *>
    43   DependencyScanningWorkerFilesystem::getOrCreateFileSystemEntry(
    44  -    const StringRef Filename) {
    45  +    const StringRef Filename, bool isForDir) {
    46     bool ShouldMinimize = shouldMinimize(Filename);
    47   
    48     if (const auto *Entry = Cache.getCachedEntry(Filename, ShouldMinimize))
    49  @@ -198,7 +198,7 @@ DependencyScanningWorkerFilesystem::getOrCreateFileSystemEntry(
    50       std::unique_lock<std::mutex> LockGuard(SharedCacheEntry.ValueLock);
    51       CachedFileSystemEntry &CacheEntry = SharedCacheEntry.Value;
    52   
    53  -    if (!CacheEntry.isValid()) {
    54  +    if (!CacheEntry.isValid() || isForDir) {
    55         auto MaybeStatus = getUnderlyingFS().status(Filename);
    56         if (!MaybeStatus && !shouldCacheStatFailures(Filename))
    57           // HACK: We need to always restat non source files if the stat fails.
    58  @@ -219,11 +219,11 @@ DependencyScanningWorkerFilesystem::getOrCreateFileSystemEntry(
    59   }
    60   
    61   llvm::ErrorOr<llvm::vfs::Status>
    62  -DependencyScanningWorkerFilesystem::status(const Twine &Path) {
    63  +DependencyScanningWorkerFilesystem::status(const Twine &Path, bool isForDir) {
    64     SmallString<256> OwnedFilename;
    65     StringRef Filename = Path.toStringRef(OwnedFilename);
    66     const llvm::ErrorOr<const CachedFileSystemEntry *> Result =
    67  -      getOrCreateFileSystemEntry(Filename);
    68  +      getOrCreateFileSystemEntry(Filename, isForDir);
    69     if (!Result)
    70       return Result.getError();
    71     return (*Result)->getStatus();
    72  diff --git a/llvm/include/llvm/Support/VirtualFileSystem.h b/llvm/include/llvm/Support/VirtualFileSystem.h
    73  index 10d2389ee079..cb82c1298671 100644
    74  --- a/llvm/include/llvm/Support/VirtualFileSystem.h
    75  +++ b/llvm/include/llvm/Support/VirtualFileSystem.h
    76  @@ -255,7 +255,7 @@ public:
    77     virtual ~FileSystem();
    78   
    79     /// Get the status of the entry at \p Path, if one exists.
    80  -  virtual llvm::ErrorOr<Status> status(const Twine &Path) = 0;
    81  +  virtual llvm::ErrorOr<Status> status(const Twine &Path, bool isForDir = false) = 0;
    82   
    83     /// Get a \p File object for the file at \p Path, if one exists.
    84     virtual llvm::ErrorOr<std::unique_ptr<File>>
    85  @@ -340,7 +340,7 @@ public:
    86     /// Pushes a file system on top of the stack.
    87     void pushOverlay(IntrusiveRefCntPtr<FileSystem> FS);
    88   
    89  -  llvm::ErrorOr<Status> status(const Twine &Path) override;
    90  +  llvm::ErrorOr<Status> status(const Twine &Path, bool isForDir = false) override;
    91     llvm::ErrorOr<std::unique_ptr<File>>
    92     openFileForRead(const Twine &Path) override;
    93     directory_iterator dir_begin(const Twine &Dir, std::error_code &EC) override;
    94  @@ -380,7 +380,7 @@ public:
    95     explicit ProxyFileSystem(IntrusiveRefCntPtr<FileSystem> FS)
    96         : FS(std::move(FS)) {}
    97   
    98  -  llvm::ErrorOr<Status> status(const Twine &Path) override {
    99  +  llvm::ErrorOr<Status> status(const Twine &Path, bool isForDir = false) override {
   100       return FS->status(Path);
   101     }
   102     llvm::ErrorOr<std::unique_ptr<File>>
   103  @@ -483,7 +483,7 @@ public:
   104     /// Return true if this file system normalizes . and .. in paths.
   105     bool useNormalizedPaths() const { return UseNormalizedPaths; }
   106   
   107  -  llvm::ErrorOr<Status> status(const Twine &Path) override;
   108  +  llvm::ErrorOr<Status> status(const Twine &Path, bool isForDir = false) override;
   109     llvm::ErrorOr<std::unique_ptr<File>>
   110     openFileForRead(const Twine &Path) override;
   111     directory_iterator dir_begin(const Twine &Dir, std::error_code &EC) override;
   112  @@ -849,7 +849,8 @@ public:
   113     create(ArrayRef<std::pair<std::string, std::string>> RemappedFiles,
   114            bool UseExternalNames, FileSystem &ExternalFS);
   115   
   116  -  ErrorOr<Status> status(const Twine &Path) override;
   117  +  ErrorOr<Status> status(const Twine &Path, bool isForDir = false) override;
   118  +
   119     ErrorOr<std::unique_ptr<File>> openFileForRead(const Twine &Path) override;
   120   
   121     std::error_code getRealPath(const Twine &Path,
   122  diff --git a/llvm/lib/Support/FileCollector.cpp b/llvm/lib/Support/FileCollector.cpp
   123  index 5854baeebbb9..656b6dc81d97 100644
   124  --- a/llvm/lib/Support/FileCollector.cpp
   125  +++ b/llvm/lib/Support/FileCollector.cpp
   126  @@ -258,7 +258,7 @@ public:
   127                                      std::shared_ptr<FileCollector> Collector)
   128         : FS(std::move(FS)), Collector(std::move(Collector)) {}
   129   
   130  -  llvm::ErrorOr<llvm::vfs::Status> status(const Twine &Path) override {
   131  +  llvm::ErrorOr<llvm::vfs::Status> status(const Twine &Path, bool isForDir = false) override {
   132       auto Result = FS->status(Path);
   133       if (Result && Result->exists())
   134         Collector->addFile(Path);
   135  diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp
   136  index 9bf0384b5f1b..1ff8be76bfcf 100644
   137  --- a/llvm/lib/Support/VirtualFileSystem.cpp
   138  +++ b/llvm/lib/Support/VirtualFileSystem.cpp
   139  @@ -260,7 +260,7 @@ public:
   140       }
   141     }
   142   
   143  -  ErrorOr<Status> status(const Twine &Path) override;
   144  +  ErrorOr<Status> status(const Twine &Path, bool isForDir = false) override;
   145     ErrorOr<std::unique_ptr<File>> openFileForRead(const Twine &Path) override;
   146     directory_iterator dir_begin(const Twine &Dir, std::error_code &EC) override;
   147   
   148  @@ -292,7 +292,7 @@ private:
   149   
   150   } // namespace
   151   
   152  -ErrorOr<Status> RealFileSystem::status(const Twine &Path) {
   153  +ErrorOr<Status> RealFileSystem::status(const Twine &Path, bool isForDir) {
   154     SmallString<256> Storage;
   155     sys::fs::file_status RealStatus;
   156     if (std::error_code EC =
   157  @@ -405,7 +405,7 @@ void OverlayFileSystem::pushOverlay(IntrusiveRefCntPtr<FileSystem> FS) {
   158     FS->setCurrentWorkingDirectory(getCurrentWorkingDirectory().get());
   159   }
   160   
   161  -ErrorOr<Status> OverlayFileSystem::status(const Twine &Path) {
   162  +ErrorOr<Status> OverlayFileSystem::status(const Twine &Path, bool isForDir) {
   163     // FIXME: handle symlinks that cross file systems
   164     for (iterator I = overlays_begin(), E = overlays_end(); I != E; ++I) {
   165       ErrorOr<Status> Status = (*I)->status(Path);
   166  @@ -914,7 +914,7 @@ bool InMemoryFileSystem::addHardLink(const Twine &FromPath,
   167                          cast<detail::InMemoryFile>(*ToNode));
   168   }
   169   
   170  -llvm::ErrorOr<Status> InMemoryFileSystem::status(const Twine &Path) {
   171  +llvm::ErrorOr<Status> InMemoryFileSystem::status(const Twine &Path, bool isForDir) {
   172     auto Node = lookupInMemoryNode(*this, Root.get(), Path);
   173     if (Node)
   174       return detail::getNodeStatus(*Node, Path);
   175  @@ -2021,7 +2021,7 @@ RedirectingFileSystem::getExternalStatus(const Twine &CanonicalPath,
   176     }
   177   }
   178   
   179  -ErrorOr<Status> RedirectingFileSystem::status(const Twine &OriginalPath) {
   180  +ErrorOr<Status> RedirectingFileSystem::status(const Twine &OriginalPath, bool isForDir) {
   181     SmallString<256> CanonicalPath;
   182     OriginalPath.toVector(CanonicalPath);
   183