Quuxplusone created this revision.
Quuxplusone added reviewers: sammccall, kadircet, dblaikie.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, MaskRay, 
ilya-biryukov.
Herald added a project: clang.

Fixes an instance of `-Woverloaded-virtual` on GCC.
Clarifies the purpose of this particular function.
Frees up a register that was being used for this pointless parameter of type 
`llvm::NoneType`.

Also eliminate `virtual` from `view(PathRef)` because it is not intended to be 
overridden.

(This is how I propose to address the underlying issue that led to D82617 
<https://reviews.llvm.org/D82617>, instead of D82617 
<https://reviews.llvm.org/D82617>. Of course the final call is 
Kadir's-or-Sam's-or-ultimately-certainly-not-mine.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82736

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/index/Background.cpp
  clang-tools-extra/clangd/support/ThreadsafeFS.cpp
  clang-tools-extra/clangd/support/ThreadsafeFS.h
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/HeaderSourceSwitchTests.cpp
  clang-tools-extra/clangd/unittests/TestFS.h

Index: clang-tools-extra/clangd/unittests/TestFS.h
===================================================================
--- clang-tools-extra/clangd/unittests/TestFS.h
+++ clang-tools-extra/clangd/unittests/TestFS.h
@@ -34,7 +34,7 @@
 class MockFS : public ThreadsafeFS {
 public:
   IntrusiveRefCntPtr<llvm::vfs::FileSystem>
-  view(llvm::NoneType) const override {
+  viewWithDefaultCWD() const override {
     return buildTestFS(Files, Timestamps);
   }
 
Index: clang-tools-extra/clangd/unittests/HeaderSourceSwitchTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/HeaderSourceSwitchTests.cpp
+++ clang-tools-extra/clangd/unittests/HeaderSourceSwitchTests.cpp
@@ -30,11 +30,11 @@
   FS.Files[FooH];
   FS.Files[Invalid];
   Optional<Path> PathResult =
-      getCorrespondingHeaderOrSource(FooCpp, FS.view(llvm::None));
+      getCorrespondingHeaderOrSource(FooCpp, FS.viewWithDefaultCWD());
   EXPECT_TRUE(PathResult.hasValue());
   ASSERT_EQ(PathResult.getValue(), FooH);
 
-  PathResult = getCorrespondingHeaderOrSource(FooH, FS.view(llvm::None));
+  PathResult = getCorrespondingHeaderOrSource(FooH, FS.viewWithDefaultCWD());
   EXPECT_TRUE(PathResult.hasValue());
   ASSERT_EQ(PathResult.getValue(), FooCpp);
 
@@ -45,7 +45,7 @@
 
   FS.Files[FooC];
   FS.Files[FooHH];
-  PathResult = getCorrespondingHeaderOrSource(FooC, FS.view(llvm::None));
+  PathResult = getCorrespondingHeaderOrSource(FooC, FS.viewWithDefaultCWD());
   EXPECT_TRUE(PathResult.hasValue());
   ASSERT_EQ(PathResult.getValue(), FooHH);
 
@@ -54,7 +54,7 @@
   auto Foo2HH = testPath("foo2.HH");
   FS.Files[Foo2C];
   FS.Files[Foo2HH];
-  PathResult = getCorrespondingHeaderOrSource(Foo2C, FS.view(llvm::None));
+  PathResult = getCorrespondingHeaderOrSource(Foo2C, FS.viewWithDefaultCWD());
   EXPECT_TRUE(PathResult.hasValue());
   ASSERT_EQ(PathResult.getValue(), Foo2HH);
 
@@ -64,13 +64,13 @@
 
   FS.Files[Foo3C];
   FS.Files[Foo3HXX];
-  PathResult = getCorrespondingHeaderOrSource(Foo3C, FS.view(llvm::None));
+  PathResult = getCorrespondingHeaderOrSource(Foo3C, FS.viewWithDefaultCWD());
   EXPECT_TRUE(PathResult.hasValue());
   ASSERT_EQ(PathResult.getValue(), Foo3HXX);
 
   // Test if asking for a corresponding file that doesn't exist returns an empty
   // string.
-  PathResult = getCorrespondingHeaderOrSource(Invalid, FS.view(llvm::None));
+  PathResult = getCorrespondingHeaderOrSource(Invalid, FS.viewWithDefaultCWD());
   EXPECT_FALSE(PathResult.hasValue());
 }
 
Index: clang-tools-extra/clangd/unittests/ClangdTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/ClangdTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdTests.cpp
@@ -274,7 +274,7 @@
   static Key<int> Secret;
   struct ContextReadingFS : public ThreadsafeFS {
     IntrusiveRefCntPtr<llvm::vfs::FileSystem>
-    view(llvm::NoneType) const override {
+    viewWithDefaultCWD() const override {
       Got = Context::current().getExisting(Secret);
       return buildTestFS({});
     }
@@ -930,7 +930,7 @@
         : CountStats(CountStats) {}
 
     IntrusiveRefCntPtr<llvm::vfs::FileSystem>
-    view(llvm::NoneType) const override {
+    viewWithDefaultCWD() const override {
       class StatRecordingVFS : public llvm::vfs::ProxyFileSystem {
       public:
         StatRecordingVFS(IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===================================================================
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -719,7 +719,7 @@
     ClangTidyOptProvider = std::make_unique<tidy::FileOptionsProvider>(
         tidy::ClangTidyGlobalOptions(),
         /* Default */ EmptyDefaults,
-        /* Override */ OverrideClangTidyOptions, TFS.view(/*CWD=*/llvm::None));
+        /* Override */ OverrideClangTidyOptions, TFS.viewWithDefaultCWD());
     Opts.GetClangTidyOptions = [&](llvm::vfs::FileSystem &,
                                    llvm::StringRef File) {
       // This function must be thread-safe and tidy option providers are not.
Index: clang-tools-extra/clangd/support/ThreadsafeFS.h
===================================================================
--- clang-tools-extra/clangd/support/ThreadsafeFS.h
+++ clang-tools-extra/clangd/support/ThreadsafeFS.h
@@ -31,19 +31,19 @@
 
   /// Obtain a vfs::FileSystem with an arbitrary initial working directory.
   virtual llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
-  view(llvm::NoneType CWD) const = 0;
+  viewWithDefaultCWD() const = 0;
 
   /// Obtain a vfs::FileSystem with a specified working directory.
   /// If the working directory can't be set (e.g. doesn't exist), logs and
   /// returns the FS anyway.
-  virtual llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
+  llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
   view(PathRef CWD) const;
 };
 
 class RealThreadsafeFS : public ThreadsafeFS {
 public:
   llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
-      view(llvm::NoneType) const override;
+      viewWithDefaultCWD() const override;
 };
 
 } // namespace clangd
Index: clang-tools-extra/clangd/support/ThreadsafeFS.cpp
===================================================================
--- clang-tools-extra/clangd/support/ThreadsafeFS.cpp
+++ clang-tools-extra/clangd/support/ThreadsafeFS.cpp
@@ -76,14 +76,14 @@
 
 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
 ThreadsafeFS::view(PathRef CWD) const {
-  auto FS = view(llvm::None);
+  auto FS = viewWithDefaultCWD();
   if (auto EC = FS->setCurrentWorkingDirectory(CWD))
     elog("VFS: failed to set CWD to {0}: {1}", CWD, EC.message());
   return FS;
 }
 
 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
-RealThreadsafeFS::view(llvm::NoneType) const {
+RealThreadsafeFS::viewWithDefaultCWD() const {
   // Avoid using memory-mapped files.
   // FIXME: Try to use a similar approach in Sema instead of relying on
   //        propagation of the 'isVolatile' flag through all layers.
Index: clang-tools-extra/clangd/index/Background.cpp
===================================================================
--- clang-tools-extra/clangd/index/Background.cpp
+++ clang-tools-extra/clangd/index/Background.cpp
@@ -380,7 +380,7 @@
   Rebuilder.loadedShard(LoadedShards);
   Rebuilder.doneLoading();
 
-  auto FS = TFS.view(/*CWD=*/llvm::None);
+  auto FS = TFS.viewWithDefaultCWD();
   llvm::DenseSet<PathRef> TUsToIndex;
   // We'll accept data from stale shards, but ensure the files get reindexed
   // soon.
Index: clang-tools-extra/clangd/SourceCode.cpp
===================================================================
--- clang-tools-extra/clangd/SourceCode.cpp
+++ clang-tools-extra/clangd/SourceCode.cpp
@@ -580,7 +580,7 @@
                                           const ThreadsafeFS &TFS) {
   auto Style = format::getStyle(format::DefaultFormatStyle, File,
                                 format::DefaultFallbackStyle, Content,
-                                TFS.view(/*CWD=*/llvm::None).get());
+                                TFS.viewWithDefaultCWD().get());
   if (!Style) {
     log("getStyle() failed for file {0}: {1}. Fallback is LLVM style.", File,
         Style.takeError());
Index: clang-tools-extra/clangd/Preamble.cpp
===================================================================
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -231,7 +231,7 @@
   class EmptyFS : public ThreadsafeFS {
   public:
     llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
-    view(llvm::NoneType) const override {
+    viewWithDefaultCWD() const override {
       return new llvm::vfs::InMemoryFileSystem;
     }
   };
@@ -259,7 +259,7 @@
       std::move(CI), nullptr, std::move(PreambleContents),
       // Provide an empty FS to prevent preprocessor from performing IO. This
       // also implies missing resolved paths for includes.
-      FS.view(llvm::None), IgnoreDiags);
+      FS.viewWithDefaultCWD(), IgnoreDiags);
   if (Clang->getFrontendOpts().Inputs.empty())
     return llvm::createStringError(llvm::inconvertibleErrorCode(),
                                    "compiler instance had no inputs");
Index: clang-tools-extra/clangd/ClangdServer.cpp
===================================================================
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -185,7 +185,7 @@
   // FIXME: call tidy options builder on the worker thread, it can do IO.
   if (GetClangTidyOptions)
     Opts.ClangTidyOpts =
-        GetClangTidyOptions(*TFS.view(/*CWD=*/llvm::None), File);
+        GetClangTidyOptions(*TFS.viewWithDefaultCWD(), File);
   Opts.SuggestMissingIncludes = SuggestMissingIncludes;
 
   // Compile command is set asynchronously during update, as it can be slow.
@@ -321,7 +321,7 @@
     return CursorPos.takeError();
   auto Style = format::getStyle(format::DefaultFormatStyle, File,
                                 format::DefaultFallbackStyle, Code,
-                                TFS.view(/*CWD=*/llvm::None).get());
+                                TFS.viewWithDefaultCWD().get());
   if (!Style)
     return Style.takeError();
 
@@ -550,7 +550,7 @@
   //  2) if 1) fails, we use the AST&Index approach, it is slower but supports
   //     different code layout.
   if (auto CorrespondingFile = getCorrespondingHeaderOrSource(
-          std::string(Path), TFS.view(llvm::None)))
+          std::string(Path), TFS.viewWithDefaultCWD()))
     return CB(std::move(CorrespondingFile));
   auto Action = [Path = Path.str(), CB = std::move(CB),
                  this](llvm::Expected<InputsAndAST> InpAST) mutable {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to