<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - clangd vs LLVM_ENABLE_THREADS=OFF"
   href="https://bugs.llvm.org/show_bug.cgi?id=41569">41569</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clangd vs LLVM_ENABLE_THREADS=OFF
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang-tools-extra
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>clangd
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>nicolasweber@gmx.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>clangd currently doesn't build with LLVM_ENABLE_THREADS=OFF (after r358664).

This makes it build:

$ git diff
diff --git a/clang-tools-extra/clangd/index/Background.cpp
b/clang-tools-extra/clangd/index/Background.cpp
index 0746a358371..2314a36908e 100644
--- a/clang-tools-extra/clangd/index/Background.cpp
+++ b/clang-tools-extra/clangd/index/Background.cpp
@@ -191,11 +191,15 @@ void BackgroundIndex::run() {
       Queue.pop_front();
     }

+#if LLVM_ENABLE_THREADS
     if (Priority != llvm::ThreadPriority::Default &&
!PreventStarvation.load())
       llvm::set_thread_priority(Priority);
+#endif
     (*Task)();
+#if LLVM_ENABLE_THREADS
     if (Priority != llvm::ThreadPriority::Default)
       llvm::set_thread_priority(llvm::ThreadPriority::Default);
+#endif

     {
       std::unique_lock<std::mutex> Lock(QueueMu);



But then a bunch of tests fail:

********************
Testing Time: 21.81s
********************
Failing Tests (17):
    Clang Tools :: clangd/background-index.test
    Extra Tools Unit Tests ::
clangd/./ClangdTests/ClangdThreadingTest.StressTest
    Extra Tools Unit Tests :: clangd/./ClangdTests/ClangdVFSTest.MemoryUsage
    Extra Tools Unit Tests ::
clangd/./ClangdTests/ClangdVFSTest.ReparseOpenedFiles
    Extra Tools Unit Tests ::
clangd/./ClangdTests/DocumentSymbolsTest.ExternSymbol
    Extra Tools Unit Tests ::
clangd/./ClangdTests/DocumentSymbolsTest.InHeaderFile
    Extra Tools Unit Tests :: clangd/./ClangdTests/GoToInclude.All
    Extra Tools Unit Tests :: clangd/./ClangdTests/TUSchedulerTests.ManyUpdates
    Extra Tools Unit Tests ::
clangd/./ClangdTests/WorkspaceSymbolsTest.AnonymousNamespace
    Extra Tools Unit Tests :: clangd/./ClangdTests/WorkspaceSymbolsTest.Enums
    Extra Tools Unit Tests ::
clangd/./ClangdTests/WorkspaceSymbolsTest.GlobalNamespaceQueries
    Extra Tools Unit Tests :: clangd/./ClangdTests/WorkspaceSymbolsTest.Globals
    Extra Tools Unit Tests ::
clangd/./ClangdTests/WorkspaceSymbolsTest.MultiFile
    Extra Tools Unit Tests ::
clangd/./ClangdTests/WorkspaceSymbolsTest.Namespaces
    Extra Tools Unit Tests :: clangd/./ClangdTests/WorkspaceSymbolsTest.Ranking
    Extra Tools Unit Tests :: clangd/./ClangdTests/WorkspaceSymbolsTest.Unnamed
    Extra Tools Unit Tests ::
clangd/./ClangdTests/WorkspaceSymbolsTest.WithLimit



Here's an example stack:

Assertion failed: (PrettyStackTraceHead == this && "Pretty stack trace entry
destruction is out of order"), function ~PrettyStackTraceEntry, file
../../llvm/lib/Support/PrettyStackTrace.cpp, line 143.
0  ClangdTests              0x000000010b1b6075
llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  ClangdTests              0x000000010b1b4e76 llvm::sys::RunSignalHandlers() +
198
2  ClangdTests              0x000000010b1b66e8 SignalHandler(int) + 264
3  libsystem_platform.dylib 0x00007fffb036bb3a _sigtramp + 26
4  libsystem_platform.dylib 0x00007fd27403eca8 _sigtramp + 3285004680
5  libsystem_c.dylib        0x00007fffb01f0420 abort + 129
6  libsystem_c.dylib        0x00007fffb01b7893 basename_r + 0
7  ClangdTests              0x000000010b15ac12
llvm::PrettyStackTraceEntry::~PrettyStackTraceEntry() + 66
8  ClangdTests              0x000000010b4f58e2 clang::ParseAST(clang::Sema&,
bool, bool) + 850
9  ClangdTests              0x000000010a73166a clang::FrontendAction::Execute()
+ 138
10 ClangdTests              0x000000010a76d375
clang::PrecompiledPreamble::Build(clang::CompilerInvocation const&,
llvm::MemoryBuffer const*, clang::PreambleBounds, clang::DiagnosticsEngine&,
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>,
std::__1::shared_ptr<clang::PCHContainerOperations>, bool,
clang::PreambleCallbacks&) + 3573
11 ClangdTests              0x000000010a1d96a5
clang::clangd::buildPreamble(llvm::StringRef, clang::CompilerInvocation&,
std::__1::shared_ptr<clang::clangd::PreambleData const>,
clang::tooling::CompileCommand const&, clang::clangd::ParseInputs const&, bool,
std::__1::function<void (clang::ASTContext&,
std::__1::shared_ptr<clang::Preprocessor>, clang::clangd::CanonicalIncludes
const&)>) + 2453
12 ClangdTests              0x000000010a252e5e void llvm::unique_function<void
()>::CallImpl<clang::clangd::(anonymous
namespace)::ASTWorker::update(clang::clangd::ParseInputs,
clang::clangd::WantDiagnostics)::$_0>(void*) + 2334
13 ClangdTests              0x000000010a24eb6e void llvm::unique_function<void
()>::CallImpl<clang::clangd::(anonymous
namespace)::ASTWorker::create(llvm::StringRef,
clang::clangd::GlobalCompilationDatabase const&,
clang::clangd::TUScheduler::ASTCache&, clang::clangd::AsyncTaskRunner*,
clang::clangd::Semaphore&, std::__1::chrono::duration<long long,
std::__1::ratio<1l, 1000000000l> >, bool,
clang::clangd::ParsingCallbacks&)::$_5>(void*) + 3726
14 ClangdTests              0x000000010a259584 void*
std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct,
std::__1::default_delete<std::__1::__thread_struct> >,
clang::clangd::AsyncTaskRunner::runAsync(llvm::Twine const&,
llvm::unique_function<void ()>)::$_4, std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> >,
llvm::unique_function<void ()>,
llvm::detail::scope_exit<clang::clangd::AsyncTaskRunner::runAsync(llvm::Twine
const&, llvm::unique_function<void ()>)::$_0> > >(void*) + 244
15 libsystem_pthread.dylib  0x00007fffb037593b _pthread_body + 180
16 libsystem_pthread.dylib  0x00007fffb0375887 _pthread_body + 0
17 libsystem_pthread.dylib  0x00007fffb037508d thread_start + 13
index AST for /clangd-test/foo.cpp (main=false):
  symbol slab: 2 symbols, 4688 bytes
  ref slab: 0 symbols, 0 refs, 136 bytes
Built preamble of size 200960 for file /clangd-test/foo.cpp
index AST for /clangd-test/foo.cpp (main=true):
  symbol slab: 0 symbols, 128 bytes
  ref slab: 0 symbols, 0 refs, 136 bytes



../../llvm/lib/Support/PrettyStackTrace.cpp assumes that if
LLVM_ENABLE_THREADS=OFF, then there are no threads, but clangd starts threads
anyways.




We don't need a great fix here (clangd with threads off won't work great), just
one that works. Options:

- If it's not too hard to do, make clangd not spawn threads if
LLVM_ENABLE_THREADS=OFF

- Add some lit setting that detects if threads are on and add a REQUIRES line
for that to those tests

- Check for LLVM_ENABLE_THREADS=OFF in the cmake build and omti clangd (and all
its tests) from the build completely in that case

- Your idea here</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>