[PATCH] D66038: [clangd] Give absolute path to clang-tidy and include-fixer. HintPath should always be absolute, some URI schemes care.

Sam McCall via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 9 15:57:59 PDT 2019


sammccall created this revision.
sammccall added reviewers: ilya-biryukov, puremourning.
Herald added subscribers: llvm-commits, cfe-commits, jfb, kadircet, arphaman, jkorous, MaskRay, hiraditya.
Herald added projects: clang, LLVM.

[Support] heavyweight_hardware_concurrency uses affinity when counting cores fails, and never returns 0

Previously it would fall back to std::thread::hardware_concurrency(),
which ignores affinity. llvm::hardware_concurrency() is better, but was
not available at the time.

Also, the case where std::thread::hardware_concurrency() returns 0 was
never handled. llvm::hardware_concurrency() never does this, so that's fixed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66038

Files:
  clang-tools-extra/clangd/ClangdUnit.cpp
  llvm/include/llvm/Support/Threading.h
  llvm/lib/Support/Threading.cpp


Index: llvm/lib/Support/Threading.cpp
===================================================================
--- llvm/lib/Support/Threading.cpp
+++ llvm/lib/Support/Threading.cpp
@@ -68,7 +68,7 @@
   // ADL.
   int NumPhysical = sys::getHostNumPhysicalCores();
   if (NumPhysical == -1)
-    return std::thread::hardware_concurrency();
+    return llvm::hardware_concurrency();
   return NumPhysical;
 }
 
Index: llvm/include/llvm/Support/Threading.h
===================================================================
--- llvm/include/llvm/Support/Threading.h
+++ llvm/include/llvm/Support/Threading.h
@@ -130,7 +130,7 @@
   /// Get the amount of currency to use for tasks requiring significant
   /// memory or other resources. Currently based on physical cores, if
   /// available for the host system, otherwise falls back to
-  /// thread::hardware_concurrency().
+  /// llvm::hardware_concurrency().
   /// Returns 1 when LLVM is configured with LLVM_ENABLE_THREADS=OFF
   unsigned heavyweight_hardware_concurrency();
 
Index: clang-tools-extra/clangd/ClangdUnit.cpp
===================================================================
--- clang-tools-extra/clangd/ClangdUnit.cpp
+++ clang-tools-extra/clangd/ClangdUnit.cpp
@@ -304,6 +304,7 @@
 
   StoreDiags ASTDiags;
   std::string Content = Buffer->getBuffer();
+  std::string Filename = Buffer->getBufferIdentifier(); // Absolute.
 
   auto Clang = prepareCompilerInstance(std::move(CI), PreamblePCH,
                                        std::move(Buffer), VFS, ASTDiags);
@@ -329,7 +330,7 @@
   llvm::Optional<tidy::ClangTidyContext> CTContext;
   {
     trace::Span Tracer("ClangTidyInit");
-    dlog("ClangTidy configuration for file {0}: {1}", MainInput.getFile(),
+    dlog("ClangTidy configuration for file {0}: {1}", Filename,
          tidy::configurationAsText(Opts.ClangTidyOpts));
     tidy::ClangTidyCheckFactories CTFactories;
     for (const auto &E : tidy::ClangTidyModuleRegistry::entries())
@@ -338,7 +339,7 @@
         tidy::ClangTidyGlobalOptions(), Opts.ClangTidyOpts));
     CTContext->setDiagnosticsEngine(&Clang->getDiagnostics());
     CTContext->setASTContext(&Clang->getASTContext());
-    CTContext->setCurrentFile(MainInput.getFile());
+    CTContext->setCurrentFile(Filename);
     CTFactories.createChecks(CTContext.getPointer(), CTChecks);
     ASTDiags.setLevelAdjuster([&CTContext](DiagnosticsEngine::Level DiagLevel,
                                            const clang::Diagnostic &Info) {
@@ -385,15 +386,15 @@
   llvm::Optional<IncludeFixer> FixIncludes;
   auto BuildDir = VFS->getCurrentWorkingDirectory();
   if (Opts.SuggestMissingIncludes && Index && !BuildDir.getError()) {
-    auto Style = getFormatStyleForFile(MainInput.getFile(), Content, VFS.get());
+    auto Style = getFormatStyleForFile(Filename, Content, VFS.get());
     auto Inserter = std::make_shared<IncludeInserter>(
-        MainInput.getFile(), Content, Style, BuildDir.get(),
+        Filename, Content, Style, BuildDir.get(),
         &Clang->getPreprocessor().getHeaderSearchInfo());
     if (Preamble) {
       for (const auto &Inc : Preamble->Includes.MainFileIncludes)
         Inserter->addExisting(Inc);
     }
-    FixIncludes.emplace(MainInput.getFile(), Inserter, *Index,
+    FixIncludes.emplace(Filename, Inserter, *Index,
                         /*IndexRequestLimit=*/5);
     ASTDiags.contributeFixes([&FixIncludes](DiagnosticsEngine::Level DiagLevl,
                                             const clang::Diagnostic &Info) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66038.214473.patch
Type: text/x-patch
Size: 3519 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190809/d2c9e651/attachment.bin>


More information about the llvm-commits mailing list