aganea created this revision. aganea added reviewers: sylvestre.ledru, rnk. Herald added a project: clang. Herald added a subscriber: cfe-commits.
This skips distro detection on Windows, thus saving a few `stat` calls for each invocation of `clang.exe`. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D70467 Files: clang/lib/Driver/Distro.cpp clang/unittests/Driver/DistroTest.cpp Index: clang/unittests/Driver/DistroTest.cpp =================================================================== --- clang/unittests/Driver/DistroTest.cpp +++ clang/unittests/Driver/DistroTest.cpp @@ -337,4 +337,37 @@ ASSERT_TRUE(Gentoo.IsGentoo()); } +#ifdef _WIN32 +TEST(DistroTest, DetectOnWindows) { + + class CountingFileSystem : public llvm::vfs::ProxyFileSystem { + public: + CountingFileSystem() : ProxyFileSystem(llvm::vfs::getRealFileSystem()) {} + + llvm::ErrorOr<llvm::vfs::Status> status(const llvm::Twine &Path) override { + ++Count; + return llvm::vfs::ProxyFileSystem::status(Path); + } + + llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>> + openFileForRead(const llvm::Twine &Path) override { + ++Count; + return llvm::vfs::ProxyFileSystem::openFileForRead(Path); + } + + unsigned Count{}; + }; + + CountingFileSystem CFileSystem; + Distro WinVFS{ CFileSystem }; + ASSERT_EQ(Distro(Distro::UnknownDistro), WinVFS); + ASSERT_GT(CFileSystem.Count, 0U); + + llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> RFS = + llvm::vfs::getRealFileSystem(); + Distro WinRFS{*RFS}; + ASSERT_EQ(Distro(Distro::UnknownDistro), WinRFS); +} +#endif + } // end anonymous namespace Index: clang/lib/Driver/Distro.cpp =================================================================== --- clang/lib/Driver/Distro.cpp +++ clang/lib/Driver/Distro.cpp @@ -18,6 +18,12 @@ using namespace clang; static Distro::DistroType DetectDistro(llvm::vfs::FileSystem &VFS) { +#ifdef _WIN32 + IntrusiveRefCntPtr<llvm::vfs::FileSystem> RealFS = + llvm::vfs::getRealFileSystem(); + if (&VFS == RealFS.get()) + return Distro::UnknownDistro; +#endif llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File = VFS.getBufferForFile("/etc/lsb-release"); if (File) {
Index: clang/unittests/Driver/DistroTest.cpp =================================================================== --- clang/unittests/Driver/DistroTest.cpp +++ clang/unittests/Driver/DistroTest.cpp @@ -337,4 +337,37 @@ ASSERT_TRUE(Gentoo.IsGentoo()); } +#ifdef _WIN32 +TEST(DistroTest, DetectOnWindows) { + + class CountingFileSystem : public llvm::vfs::ProxyFileSystem { + public: + CountingFileSystem() : ProxyFileSystem(llvm::vfs::getRealFileSystem()) {} + + llvm::ErrorOr<llvm::vfs::Status> status(const llvm::Twine &Path) override { + ++Count; + return llvm::vfs::ProxyFileSystem::status(Path); + } + + llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>> + openFileForRead(const llvm::Twine &Path) override { + ++Count; + return llvm::vfs::ProxyFileSystem::openFileForRead(Path); + } + + unsigned Count{}; + }; + + CountingFileSystem CFileSystem; + Distro WinVFS{ CFileSystem }; + ASSERT_EQ(Distro(Distro::UnknownDistro), WinVFS); + ASSERT_GT(CFileSystem.Count, 0U); + + llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> RFS = + llvm::vfs::getRealFileSystem(); + Distro WinRFS{*RFS}; + ASSERT_EQ(Distro(Distro::UnknownDistro), WinRFS); +} +#endif + } // end anonymous namespace Index: clang/lib/Driver/Distro.cpp =================================================================== --- clang/lib/Driver/Distro.cpp +++ clang/lib/Driver/Distro.cpp @@ -18,6 +18,12 @@ using namespace clang; static Distro::DistroType DetectDistro(llvm::vfs::FileSystem &VFS) { +#ifdef _WIN32 + IntrusiveRefCntPtr<llvm::vfs::FileSystem> RealFS = + llvm::vfs::getRealFileSystem(); + if (&VFS == RealFS.get()) + return Distro::UnknownDistro; +#endif llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File = VFS.getBufferForFile("/etc/lsb-release"); if (File) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits