[PATCH] D70467: [Distro] Bypass distro detection on Windows
Alexandre Ganea via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 19 14:51:32 PST 2019
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) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70467.230153.patch
Type: text/x-patch
Size: 1826 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191119/889ba5d3/attachment-0001.bin>
More information about the cfe-commits
mailing list