https://github.com/cachemeifyoucan created https://github.com/llvm/llvm-project/pull/244339
Add a query to vfs::Status that returns whether any of the execute permissions is set, so that clients checking whether a file found through a VFS is executable don't have to test the permission bits by hand. Update MSVC toolchain to use the new API. Unlike sys::fs::can_execute, it does not check whether the current process is allowed to execute the file. >From 2b7c640ce1c05abc438b53e005b3decd843c9220 Mon Sep 17 00:00:00 2001 From: Steven Wu <[email protected]> Date: Thu, 19 Nov 2026 10:48:48 -0800 Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?= =?UTF-8?q?l=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.7 --- clang/lib/Driver/ToolChains/MSVC.cpp | 4 +-- llvm/include/llvm/Support/VirtualFileSystem.h | 5 ++++ llvm/lib/Support/VirtualFileSystem.cpp | 4 +++ .../Support/VirtualFileSystemTest.cpp | 27 +++++++++++++++++++ 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/clang/lib/Driver/ToolChains/MSVC.cpp b/clang/lib/Driver/ToolChains/MSVC.cpp index 8f4c8f89ce58f9..0bf7e8874edfd7 100644 --- a/clang/lib/Driver/ToolChains/MSVC.cpp +++ b/clang/lib/Driver/ToolChains/MSVC.cpp @@ -44,9 +44,7 @@ using namespace llvm::opt; static bool canExecute(llvm::vfs::FileSystem &VFS, StringRef Path) { auto Status = VFS.status(Path); - if (!Status) - return false; - return (Status->getPermissions() & llvm::sys::fs::perms::all_exe) != 0; + return Status && Status->isExecutable(); } // Try to find Exe from a Visual Studio distribution. This first tries to find diff --git a/llvm/include/llvm/Support/VirtualFileSystem.h b/llvm/include/llvm/Support/VirtualFileSystem.h index c2a84963204405..1b5e0f3b19dbad 100644 --- a/llvm/include/llvm/Support/VirtualFileSystem.h +++ b/llvm/include/llvm/Support/VirtualFileSystem.h @@ -109,6 +109,11 @@ class Status { LLVM_ABI bool isStatusKnown() const; LLVM_ABI bool exists() const; /// @} + + /// Returns true if any of the owner, group, or others execute permissions is + /// set. Unlike llvm::sys::fs::can_execute, this does not check whether the + /// current process is allowed to execute the file. + LLVM_ABI bool isExecutable() const; }; /// Represents an open file. diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp index 38d1e876a7a235..50a657c9d08907 100644 --- a/llvm/lib/Support/VirtualFileSystem.cpp +++ b/llvm/lib/Support/VirtualFileSystem.cpp @@ -110,6 +110,10 @@ bool Status::exists() const { return isStatusKnown() && Type != file_type::file_not_found; } +bool Status::isExecutable() const { + return (Perms & sys::fs::all_exe) != sys::fs::no_perms; +} + File::~File() = default; FileSystem::~FileSystem() = default; diff --git a/llvm/unittests/Support/VirtualFileSystemTest.cpp b/llvm/unittests/Support/VirtualFileSystemTest.cpp index 1db4894e957197..ac356d32c755c5 100644 --- a/llvm/unittests/Support/VirtualFileSystemTest.cpp +++ b/llvm/unittests/Support/VirtualFileSystemTest.cpp @@ -273,6 +273,33 @@ TEST(VirtualFileSystemTest, StatusQueries) { EXPECT_FALSE(Status->equivalent(*Status2)); } +TEST(VirtualFileSystemTest, StatusIsExecutable) { + auto D = makeIntrusiveRefCnt<DummyFileSystem>(); + auto IsExecutable = [&](StringRef Path) { + ErrorOr<vfs::Status> Status = D->status(Path); + EXPECT_FALSE(Status.getError()); + return Status && Status->isExecutable(); + }; + + D->addRegularFile("/all"); + EXPECT_TRUE(IsExecutable("/all")); + + D->addRegularFile("/owner", sys::fs::owner_exe); + EXPECT_TRUE(IsExecutable("/owner")); + + D->addRegularFile("/group", sys::fs::group_exe); + EXPECT_TRUE(IsExecutable("/group")); + + D->addRegularFile("/others", sys::fs::others_exe); + EXPECT_TRUE(IsExecutable("/others")); + + D->addRegularFile("/none", sys::fs::all_read | sys::fs::all_write); + EXPECT_FALSE(IsExecutable("/none")); + + D->addDirectory("/dir", sys::fs::all_read); + EXPECT_FALSE(IsExecutable("/dir")); +} + TEST(VirtualFileSystemTest, BaseOnlyOverlay) { auto D = makeIntrusiveRefCnt<DummyFileSystem>(); ErrorOr<vfs::Status> Status((std::error_code())); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
