diff --git a/clang/lib/Driver/Distro.cpp b/clang/lib/Driver/Distro.cpp --- a/clang/lib/Driver/Distro.cpp +++ b/clang/lib/Driver/Distro.cpp @@ -18,6 +18,12 @@ using namespace clang; static Distro::DistroType DetectDistro(llvm::vfs::FileSystem &VFS) { +#ifdef _WIN32 + IntrusiveRefCntPtr RealFS = + llvm::vfs::getRealFileSystem(); + if (&VFS == RealFS.get()) + return Distro::UnknownDistro; +#endif llvm::ErrorOr> File = VFS.getBufferForFile("/etc/lsb-release"); if (File) { diff --git a/clang/unittests/Driver/DistroTest.cpp b/clang/unittests/Driver/DistroTest.cpp --- a/clang/unittests/Driver/DistroTest.cpp +++ b/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 status(const llvm::Twine &Path) override { + ++Count; + return llvm::vfs::ProxyFileSystem::status(Path); + } + + llvm::ErrorOr> + 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 RFS = + llvm::vfs::getRealFileSystem(); + Distro WinRFS{*RFS}; + ASSERT_EQ(Distro(Distro::UnknownDistro), WinRFS); +} +#endif + } // end anonymous namespace