Skip to content

[libc++] Don't try to wait on a thread that hasn't started in std::async #125433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2025

Conversation

philnik777
Copy link
Contributor

If the creation of a thread fails, this causes an idle loop that will never end because the thread wasn't started in the first place.

Fixes #125428

@philnik777 philnik777 requested a review from a team as a code owner February 2, 2025 21:08
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Feb 2, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 2, 2025

@llvm/pr-subscribers-libcxx

Author: Nikolas Klauser (philnik777)

Changes

If the creation of a thread fails, this causes an idle loop that will never end because the thread wasn't started in the first place.

Fixes #125428


Full diff: https://github.com/llvm/llvm-project/pull/125433.diff

2 Files Affected:

  • (modified) libcxx/include/future (+4-2)
  • (added) libcxx/test/std/thread/futures/futures.async/thread_create_failure.pass.cpp (+46)
diff --git a/libcxx/include/future b/libcxx/include/future
index db1f624244b8f77..514d4c3d633d6cf 100644
--- a/libcxx/include/future
+++ b/libcxx/include/future
@@ -865,7 +865,8 @@ void __async_assoc_state<_Rp, _Fp>::__execute() {
 
 template <class _Rp, class _Fp>
 void __async_assoc_state<_Rp, _Fp>::__on_zero_shared() _NOEXCEPT {
-  this->wait();
+  if (base::__state_ & base::__constructed)
+    this->wait();
   base::__on_zero_shared();
 }
 
@@ -902,7 +903,8 @@ void __async_assoc_state<void, _Fp>::__execute() {
 
 template <class _Fp>
 void __async_assoc_state<void, _Fp>::__on_zero_shared() _NOEXCEPT {
-  this->wait();
+  if (base::__state_ & base::__constructed)
+    this->wait();
   base::__on_zero_shared();
 }
 
diff --git a/libcxx/test/std/thread/futures/futures.async/thread_create_failure.pass.cpp b/libcxx/test/std/thread/futures/futures.async/thread_create_failure.pass.cpp
new file mode 100644
index 000000000000000..ac5db590dbd8d1d
--- /dev/null
+++ b/libcxx/test/std/thread/futures/futures.async/thread_create_failure.pass.cpp
@@ -0,0 +1,46 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: no-threads
+
+// There is no way to limit the number of threads on windows
+// UNSUPPORTED: msvc
+
+#include <cassert>
+#include <future>
+#include <system_error>
+
+#if __has_include(<sys/resource.h>)
+#  include <sys/resource.h>
+#  ifdef RLIMIT_NPROC
+void force_thread_creation_failure() {
+  rlimit lim = {1, 1};
+  setrlimit(RLIMIT_NPROC, &lim);
+}
+#  else
+#    error "No known way to force only one thread being available"
+#  endif
+#else
+#  error "No known way to force only one thread being available"
+#endif
+
+int main() {
+  force_thread_creation_failure();
+
+  try {
+    auto fut = std::async(std::launch::async, [] { return 1; });
+    assert(false);
+  } catch (const std::system_error&) {
+  }
+
+  try {
+    auto fut = std::async(std::launch::async, [] { return; });
+    assert(false);
+  } catch (const std::system_error&) {
+  }
+}

@philnik777 philnik777 force-pushed the fix_async_thread_create_failure branch from 5504050 to d1944d4 Compare February 4, 2025 13:05
@philnik777 philnik777 force-pushed the fix_async_thread_create_failure branch 2 times, most recently from ab20aa6 to b20ce83 Compare February 20, 2025 08:32
@philnik777 philnik777 force-pushed the fix_async_thread_create_failure branch from b20ce83 to cc88f55 Compare February 22, 2025 09:54
@philnik777 philnik777 force-pushed the fix_async_thread_create_failure branch from cc88f55 to 16cec3e Compare February 22, 2025 21:34
@philnik777 philnik777 merged commit 11766a4 into llvm:main Feb 25, 2025
77 of 81 checks passed
@philnik777 philnik777 deleted the fix_async_thread_create_failure branch February 25, 2025 12:33
@slotosch
Copy link

Thank you very much for this quick fix

@philnik777
Copy link
Contributor Author

Thank you very much for this quick fix

You're welcome!

thurstond added a commit to thurstond/llvm-project that referenced this pull request Feb 25, 2025
Fixes hwasan buildbot failure
(https://lab.llvm.org/buildbot/#/builders/55/builds/7536/steps/10/logs/stdio) introduced in llvm#125433 by excluding this test for hwasan, similar to the existing exclusion of asan.
thurstond added a commit that referenced this pull request Feb 25, 2025
Fixes hwasan buildbot failure

(https://lab.llvm.org/buildbot/#/builders/55/builds/7536/steps/10/logs/stdio)
introduced in #125433 by
excluding this test for hwasan, similar to the existing exclusion of
asan.
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Feb 25, 2025
Fixes hwasan buildbot failure

(https://lab.llvm.org/buildbot/#/builders/55/builds/7536/steps/10/logs/stdio)
introduced in llvm/llvm-project#125433 by
excluding this test for hwasan, similar to the existing exclusion of
asan.
@mysterymath
Copy link
Contributor

mysterymath commented Feb 25, 2025

This looks like the only plausible change in a blamelist for a Fuchsia test regression when trying to roll HEAD clang:
https://issuetracker.google.com/399181046

It includes the error libc++abi: terminating due to uncaught exception of type std::__2::future_error: Operation not permitted on an object without an associated state..

If this is the culprit, it's either an issue with this change generally or with our usage of std::future. Does it seem plausible that this change could change behavior in a breaky way? Regardless, I can start reading up on the context for this change and looking into the error on our side.

@philnik777
Copy link
Contributor Author

I guess it's possible if somehow the __constructed bit isn't set but should be.

@mysterymath
Copy link
Contributor

A bit more information; I was able to pull this stack trace:

17:30:02.376092 test223:    #3    0x00000041d5f3ab5e in std::__terminate(std::terminate_handler) libcxxabi/src/cxa_handlers.cpp:59 <libc++abi.so.1>+0x33b5e from CFI
17:30:02.376097 test223:    #4    0x00000041d5f3df06 in __cxxabiv1::failed_throw(__cxxabiv1::__cxa_exception*) libcxxabi/src/cxa_exception.cpp:152 <libc++abi.so.1>+0x36f06 from CFI
17:30:02.376101 test223:    #5    0x00000041d5f3def0 in __cxa_throw(void*, std::type_info*, void (*)(void*)) libcxxabi/src/cxa_exception.cpp:299 <libc++abi.so.1>+0x36ef0 from CFI
17:30:02.376105 test223:    #6    0x000003f1a252333e in std::__2::__throw_future_error(std::__2::future_errc) /b/s/w/ir/x/w/llvm_build/include/c++/v1/future:516 <libc++.so.2>+0xa033e from CFI
17:30:02.376128 test223:    #7    0x000003f1a252390b in std::__2::__assoc_sub_state::__execute(std::__2::__assoc_sub_state*) libcxx/src/future.cpp:125 <libc++.so.2>+0xa090b from CFI
17:30:02.376133 test223:    #8    0x0000003a24ba54e5 in std::__2::__invoke<void(std::__2::__async_assoc_state<void, std::__2::__async_func<(lambda at../../sdk/lib/async/test/executor_tests.cc:83:44)>>::*)(), std::__2::__async_assoc_state<void, std::__2::__async_func<(lambda at../../sdk/lib/async/test/executor_tests.cc:83:44)>>*, void>(void (std::__2::__async_assoc_state<void, std::__2::__async_func<(lambda at ../../sdk/lib/async/test/executor_tests.cc:83:44)> >::*)(std::__2::__async_assoc_state<void, std::__2::__async_func<(lambda at ../../sdk/lib/async/test/executor_tests.cc:83:44)> >*)&&, std::__2::__async_assoc_state<void, std::__2::__async_func<(lambda at ../../sdk/lib/async/test/executor_tests.cc:83:44)> >*&&) ../../prebuilt/third_party/clang/custom/include/c++/v1/__type_traits/invoke.h:147 <<VMO#3004932=blob-5dfe767c>>+0x4e4e5 from CFI
17:30:02.376137 test223:    #9    0x0000003a24ba543e in std::__2::__thread_execute<std::__2::unique_ptr<std::__2::__thread_struct, std::__2::default_delete<std::__2::__thread_struct>>, void(std::__2::__async_assoc_state<void, std::__2::__async_func<(lambda at../../sdk/lib/async/test/executor_tests.cc:83:44)>>::*)(), std::__2::__async_assoc_state<void, std::__2::__async_func<(lambda at../../sdk/lib/async/test/executor_tests.cc:83:44)>>*, 2UL>(std::__2::tuple<std::__2::unique_ptr<std::__2::__thread_struct, std::__2::default_delete<std::__2::__thread_struct> >, void (std::__2::__async_assoc_state<void, std::__2::__async_func<(lambda at ../../sdk/lib/async/test/executor_tests.cc:83:44)> >::*)(), std::__2::__async_assoc_state<void, std::__2::__async_func<(lambda at ../../sdk/lib/async/test/executor_tests.cc:83:44)> > *>&, std::__2::__tuple_indices<2UL>) ../../prebuilt/third_party/clang/custom/include/c++/v1/__thread/thread.h:199 <<VMO#3004932=blob-5dfe767c>>+0x4e43e from CFI
17:30:02.376141 test223:    #10   0x0000003a24ba523c in std::__2::__thread_proxy<std::__2::tuple<std::__2::unique_ptr<std::__2::__thread_struct, std::__2::default_delete<std::__2::__thread_struct>>, void(std::__2::__async_assoc_state<void, std::__2::__async_func<(lambda at../../sdk/lib/async/test/executor_tests.cc:83:44)>>::*)(), std::__2::__async_assoc_state<void, std::__2::__async_func<(lambda at../../sdk/lib/async/test/executor_tests.cc:83:44)>>*>>(void*) ../../prebuilt/third_party/clang/custom/include/c++/v1/__thread/thread.h:208 <<VMO#3004932=blob-5dfe767c>>+0x4e23c from CFI

@kadircet
Copy link
Member

kadircet commented Mar 6, 2025

hi folks, we've also started seeing some use-after-free issues after this patch in clangd. I've sent out https://github.com/llvm/llvm-project/pull/130077/files to stop the bleeding for now, but I feel like there's something off with this change.

Pattern in clangd looks like:

void bar() {
   std::future<...> x = std::async(std::launch::async, [some_state]{ // uses some_state; });
   // destruct x, don't block explicitly for completion of async task. relying on 
}

after this patch destructor doesn't block on completion of async task in the future, as a result we free some_state and hit use after free as the execution of the async task makes progress.

so this code is relying on:

I am not an expert here, so my reading of the standard might be wrong hence I am leaving the final call to you folks. but I feel like this is a rather common pattern and changing behavior here might yield breakages in existing code.

Moreover patch description mentions Don't try to wait on a thread that hasn't started, that's clearly not the case here. we've got a task that's already running hence I feel like this is not an intended affect of this patch (LMK if I can provide more info).

full asan failure
=================================================================
==3188==ERROR: AddressSanitizer: heap-use-after-free on address 0x7c72c1ac8c40 at pc 0x7f5736d7521b bp 0x7b52a9c39dc0 sp 0x7b52a9c39db8
READ of size 8 at 0x7c72c1ac8c40 thread T49
    #0 0x7f5736d7521a in __invoke<void (std::__u::__async_assoc_state<std::__u::pair<bool, clang::clangd::SymbolSlab>, std::__u::__async_func<(lambda at [third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.h:130](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.h?l=130&ws=eaeltsin/6692&snapshot=611):7), llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>, clang::clangd::Context> >::*)(), std::__u::__async_assoc_state<std::__u::pair<bool, clang::clangd::SymbolSlab>, std::__u::__async_func<(lambda at [third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.h:130](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.h?l=130&ws=eaeltsin/6692&snapshot=611):7), llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>, clang::clangd::Context> > *, void> [third_party/crosstool/v18/llvm_unstable/src/libcxx/include/__type_traits/invoke.h:147](https://cs.corp.google.com/piper///depot/google3/third_party/crosstool/v18/llvm_unstable/src/libcxx/include/__type_traits/invoke.h?l=147&ws=eaeltsin/6692&snapshot=611):25
    #1 0x7f5736d7521a in __thread_execute<std::__u::unique_ptr<std::__u::__thread_struct, std::__u::default_delete<std::__u::__thread_struct> >, void (std::__u::__async_assoc_state<std::__u::pair<bool, clang::clangd::SymbolSlab>, std::__u::__async_func<(lambda at [third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.h:130](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.h?l=130&ws=eaeltsin/6692&snapshot=611):7), llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>, clang::clangd::Context> >::*)(), std::__u::__async_assoc_state<std::__u::pair<bool, clang::clangd::SymbolSlab>, std::__u::__async_func<(lambda at [third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.h:130](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.h?l=130&ws=eaeltsin/6692&snapshot=611):7), llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>, clang::clangd::Context> > *, 2UL> [third_party/crosstool/v18/llvm_unstable/src/libcxx/include/__thread/thread.h:200](https://cs.corp.google.com/piper///depot/google3/third_party/crosstool/v18/llvm_unstable/src/libcxx/include/__thread/thread.h?l=200&ws=eaeltsin/6692&snapshot=611):3
    #2 0x7f5736d7521a in void* std::__u::__thread_proxy<std::__u::tuple<std::__u::unique_ptr<std::__u::__thread_struct, std::__u::default_delete<std::__u::__thread_struct>>, void (std::__u::__async_assoc_state<std::__u::pair<bool, clang::clangd::SymbolSlab>, std::__u::__async_func<std::__u::future<std::__u::pair<bool, clang::clangd::SymbolSlab>> clang::clangd::runAsync<std::__u::pair<bool, clang::clangd::SymbolSlab>>(llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>)::'lambda'(llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>&&, clang::clangd::Context), llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>, clang::clangd::Context>>::*)(), std::__u::__async_assoc_state<std::__u::pair<bool, clang::clangd::SymbolSlab>, std::__u::__async_func<std::__u::future<std::__u::pair<bool, clang::clangd::SymbolSlab>> clang::clangd::runAsync<std::__u::pair<bool, clang::clangd::SymbolSlab>>(llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>)::'lambda'(llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>&&, clang::clangd::Context), llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>, clang::clangd::Context>>*>>(void*) [third_party/crosstool/v18/llvm_unstable/src/libcxx/include/__thread/thread.h:209](https://cs.corp.google.com/piper///depot/google3/third_party/crosstool/v18/llvm_unstable/src/libcxx/include/__thread/thread.h?l=209&ws=eaeltsin/6692&snapshot=611):3
    #3 0x55a92182aef0 in asan_thread_start(void*) [third_party/llvm/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp:239](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp?l=239&ws=eaeltsin/6692&snapshot=611):28
    #4 0x7f5726b477da in start_thread (/usr/grte/v5/lib64/libpthread.so.0+0xb7da) (BuildId: b431ea3122d3e21a60bfe317db5010e3)

0x7c72c1ac8c40 is located 0 bytes inside of 296-byte region [0x7c72c1ac8c40,0x7c72c1ac8d68)
freed by thread T48 (task:foo.cpp) here:
    #0 0x55a921868842 in operator delete(void*, unsigned long) [third_party/llvm/llvm-project/compiler-rt/lib/asan/asan_new_delete.cpp:155](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/compiler-rt/lib/asan/asan_new_delete.cpp?l=155&ws=eaeltsin/6692&snapshot=611):3
    #1 0x7f5736d74a37 in std::__u::__async_assoc_state<std::__u::pair<bool, clang::clangd::SymbolSlab>, std::__u::__async_func<std::__u::future<std::__u::pair<bool, clang::clangd::SymbolSlab>> clang::clangd::runAsync<std::__u::pair<bool, clang::clangd::SymbolSlab>>(llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>)::'lambda'(llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>&&, clang::clangd::Context), llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>, clang::clangd::Context>>::~__async_assoc_state() third_party/crosstool/v18/llvm_unstable/src/libcxx/include/future:837:7
    #2 0x7f5736d74ab9 in __on_zero_shared third_party/crosstool/v18/llvm_unstable/src/libcxx/include/future:616:3
    #3 0x7f5736d74ab9 in std::__u::__async_assoc_state<std::__u::pair<bool, clang::clangd::SymbolSlab>, std::__u::__async_func<std::__u::future<std::__u::pair<bool, clang::clangd::SymbolSlab>> clang::clangd::runAsync<std::__u::pair<bool, clang::clangd::SymbolSlab>>(llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>)::'lambda'(llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>&&, clang::clangd::Context), llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>, clang::clangd::Context>>::__on_zero_shared() third_party/crosstool/v18/llvm_unstable/src/libcxx/include/future:870:9
    #4 0x7f5736d37029 in __release_shared [third_party/crosstool/v18/llvm_unstable/src/libcxx/include/__memory/shared_count.h:92](https://cs.corp.google.com/piper///depot/google3/third_party/crosstool/v18/llvm_unstable/src/libcxx/include/__memory/shared_count.h?l=92&ws=eaeltsin/6692&snapshot=611):7
    #5 0x7f5736d37029 in ~future third_party/crosstool/v18/llvm_unstable/src/libcxx/include/future:987:15
    #6 0x7f5736d37029 in ~SpeculativeFuzzyFind [third_party/llvm/llvm-project/clang-tools-extra/clangd/CodeComplete.h:269](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/CodeComplete.h?l=269&ws=eaeltsin/6692&snapshot=611):8
    #7 0x7f5736d37029 in std::__u::__optional_destruct_base<clang::clangd::SpeculativeFuzzyFind, false>::~__optional_destruct_base() third_party/crosstool/v18/llvm_unstable/src/libcxx/include/optional:300:15
    #8 0x7f5736d36967 in operator() [third_party/llvm/llvm-project/clang-tools-extra/clangd/ClangdServer.cpp:475](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/ClangdServer.cpp?l=475&ws=eaeltsin/6692&snapshot=611):3
    #9 0x7f5736d36967 in void llvm::detail::UniqueFunctionBase<void, llvm::Expected<clang::clangd::InputsAndPreamble>>::CallImpl<clang::clangd::ClangdServer::codeComplete(llvm::StringRef, clang::clangd::Position, clang::clangd::CodeCompleteOptions const&, llvm::unique_function<void (llvm::Expected<clang::clangd::CodeCompleteResult>)>)::$_0>(void*, llvm::Expected<clang::clangd::InputsAndPreamble>&) [third_party/llvm/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:222](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h?l=222&ws=eaeltsin/6692&snapshot=611):12
    #10 0x7f57370b022c in operator() [third_party/llvm/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:387](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h?l=387&ws=eaeltsin/6692&snapshot=611):12
    #11 0x7f57370b022c in operator() [third_party/llvm/llvm-project/clang-tools-extra/clangd/TUScheduler.cpp:1811](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/TUScheduler.cpp?l=1811&ws=eaeltsin/6692&snapshot=611):5
    #12 0x7f57370b022c in void llvm::detail::UniqueFunctionBase<void>::CallImpl<clang::clangd::TUScheduler::runWithPreamble(llvm::StringRef, llvm::StringRef, clang::clangd::TUScheduler::PreambleConsistency, llvm::unique_function<void (llvm::Expected<clang::clangd::InputsAndPreamble>)>)::$_0>(void*) [third_party/llvm/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:222](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h?l=222&ws=eaeltsin/6692&snapshot=611):12
    #13 0x7f5722f1eeaf in operator() [third_party/llvm/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:387](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h?l=387&ws=eaeltsin/6692&snapshot=611):12
    #14 0x7f5722f1eeaf in operator() [third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:101](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp?l=101&ws=eaeltsin/6692&snapshot=611):5
    #15 0x7f5722f1eeaf in operator()<(lambda at [third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:98](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp?l=98&ws=eaeltsin/6692&snapshot=611):15) &> [third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h:45](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h?l=45&ws=eaeltsin/6692&snapshot=611):11
    #16 0x7f5722f1eeaf in __invoke<(lambda at [third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h:44](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h?l=44&ws=eaeltsin/6692&snapshot=611):9), (lambda at [third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:98](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp?l=98&ws=eaeltsin/6692&snapshot=611):15) &> [third_party/crosstool/v18/llvm_unstable/src/libcxx/include/__type_traits/invoke.h:179](https://cs.corp.google.com/piper///depot/google3/third_party/crosstool/v18/llvm_unstable/src/libcxx/include/__type_traits/invoke.h?l=179&ws=eaeltsin/6692&snapshot=611):25
    #17 0x7f5722f1eeaf in __apply_tuple_impl<(lambda at [third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h:44](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h?l=44&ws=eaeltsin/6692&snapshot=611):9), std::__u::tuple<(lambda at [third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:98](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp?l=98&ws=eaeltsin/6692&snapshot=611):15)> &, 0UL> third_party/crosstool/v18/llvm_unstable/src/libcxx/include/tuple:1380:5
    #18 0x7f5722f1eeaf in apply<(lambda at [third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h:44](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h?l=44&ws=eaeltsin/6692&snapshot=611):9), std::__u::tuple<(lambda at [third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:98](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp?l=98&ws=eaeltsin/6692&snapshot=611):15)> &> third_party/crosstool/v18/llvm_unstable/src/libcxx/include/tuple:1384:5
    #19 0x7f5722f1eeaf in GenericThreadProxy<std::__u::tuple<(lambda at [third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:98](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp?l=98&ws=eaeltsin/6692&snapshot=611):15)> > [third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h:43](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h?l=43&ws=eaeltsin/6692&snapshot=611):5
    #20 0x7f5722f1eeaf in void* llvm::thread::ThreadProxy<std::__u::tuple<clang::clangd::AsyncTaskRunner::runAsync(llvm::Twine const&, llvm::unique_function<void ()>)::$_1>>(void*) [third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h:57](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h?l=57&ws=eaeltsin/6692&snapshot=611):5
    #21 0x55a92182aef0 in asan_thread_start(void*) [third_party/llvm/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp:239](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp?l=239&ws=eaeltsin/6692&snapshot=611):28
    #22 0x7f5726b477da in start_thread (/usr/grte/v5/lib64/libpthread.so.0+0xb7da) (BuildId: b431ea3122d3e21a60bfe317db5010e3)

previously allocated by thread T48 (task:foo.cpp) here:
    #0 0x55a921867bbd in operator new(unsigned long) [third_party/llvm/llvm-project/compiler-rt/lib/asan/asan_new_delete.cpp:86](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/compiler-rt/lib/asan/asan_new_delete.cpp?l=86&ws=eaeltsin/6692&snapshot=611):3
    #1 0x7f5736d7441e in std::__u::future<std::__u::pair<bool, clang::clangd::SymbolSlab>> std::__u::__make_async_assoc_state<std::__u::pair<bool, clang::clangd::SymbolSlab>, std::__u::__async_func<std::__u::future<std::__u::pair<bool, clang::clangd::SymbolSlab>> clang::clangd::runAsync<std::__u::pair<bool, clang::clangd::SymbolSlab>>(llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>)::'lambda'(llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>&&, clang::clangd::Context), llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>, clang::clangd::Context>>(std::__u::__async_func<std::__u::future<std::__u::pair<bool, clang::clangd::SymbolSlab>> clang::clangd::runAsync<std::__u::pair<bool, clang::clangd::SymbolSlab>>(llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>)::'lambda'(llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>&&, clang::clangd::Context), llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>, clang::clangd::Context>&&) third_party/crosstool/v18/llvm_unstable/src/libcxx/include/future:1833:7
    #2 0x7f5736d7408e in std::__u::future<std::__u::__invoke_result<__decay(std::__u::pair<bool, clang::clangd::SymbolSlab>), __decay(llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>), __decay(clang::clangd::Context)>::type> std::__u::async<std::__u::future<std::__u::pair<bool, clang::clangd::SymbolSlab>> clang::clangd::runAsync<std::__u::pair<bool, clang::clangd::SymbolSlab>>(llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>)::'lambda'(llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>&&, clang::clangd::Context), llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>, clang::clangd::Context>(std::__u::launch, std::__u::pair<bool, clang::clangd::SymbolSlab>&&, llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>&&, clang::clangd::Context&&) third_party/crosstool/v18/llvm_unstable/src/libcxx/include/future:1878:14
    #3 0x7f5736d52c60 in runAsync<std::__u::pair<bool, clang::clangd::SymbolSlab> > [third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.h:128](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.h?l=128&ws=eaeltsin/6692&snapshot=611):10
    #4 0x7f5736d52c60 in startAsyncFuzzyFind [third_party/llvm/llvm-project/clang-tools-extra/clangd/CodeComplete.cpp:1515](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/CodeComplete.cpp?l=1515&ws=eaeltsin/6692&snapshot=611):10
    #5 0x7f5736d52c60 in run [third_party/llvm/llvm-project/clang-tools-extra/clangd/CodeComplete.cpp:1657](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/CodeComplete.cpp?l=1657&ws=eaeltsin/6692&snapshot=611):31
    #6 0x7f5736d52c60 in clang::clangd::codeComplete(llvm::StringRef, clang::clangd::Position, clang::clangd::PreambleData const*, clang::clangd::ParseInputs const&, clang::clangd::CodeCompleteOptions, clang::clangd::SpeculativeFuzzyFind*) [third_party/llvm/llvm-project/clang-tools-extra/clangd/CodeComplete.cpp:2304](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/CodeComplete.cpp?l=2304&ws=eaeltsin/6692&snapshot=611):32
    #7 0x7f5736d365ca in operator() [third_party/llvm/llvm-project/clang-tools-extra/clangd/ClangdServer.cpp:460](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/ClangdServer.cpp?l=460&ws=eaeltsin/6692&snapshot=611):33
    #8 0x7f5736d365ca in void llvm::detail::UniqueFunctionBase<void, llvm::Expected<clang::clangd::InputsAndPreamble>>::CallImpl<clang::clangd::ClangdServer::codeComplete(llvm::StringRef, clang::clangd::Position, clang::clangd::CodeCompleteOptions const&, llvm::unique_function<void (llvm::Expected<clang::clangd::CodeCompleteResult>)>)::$_0>(void*, llvm::Expected<clang::clangd::InputsAndPreamble>&) [third_party/llvm/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:222](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h?l=222&ws=eaeltsin/6692&snapshot=611):12
    #9 0x7f57370b022c in operator() [third_party/llvm/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:387](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h?l=387&ws=eaeltsin/6692&snapshot=611):12
    #10 0x7f57370b022c in operator() [third_party/llvm/llvm-project/clang-tools-extra/clangd/TUScheduler.cpp:1811](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/TUScheduler.cpp?l=1811&ws=eaeltsin/6692&snapshot=611):5
    #11 0x7f57370b022c in void llvm::detail::UniqueFunctionBase<void>::CallImpl<clang::clangd::TUScheduler::runWithPreamble(llvm::StringRef, llvm::StringRef, clang::clangd::TUScheduler::PreambleConsistency, llvm::unique_function<void (llvm::Expected<clang::clangd::InputsAndPreamble>)>)::$_0>(void*) [third_party/llvm/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:222](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h?l=222&ws=eaeltsin/6692&snapshot=611):12
    #12 0x7f5722f1eeaf in operator() [third_party/llvm/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:387](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h?l=387&ws=eaeltsin/6692&snapshot=611):12
    #13 0x7f5722f1eeaf in operator() [third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:101](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp?l=101&ws=eaeltsin/6692&snapshot=611):5
    #14 0x7f5722f1eeaf in operator()<(lambda at [third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:98](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp?l=98&ws=eaeltsin/6692&snapshot=611):15) &> [third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h:45](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h?l=45&ws=eaeltsin/6692&snapshot=611):11
    #15 0x7f5722f1eeaf in __invoke<(lambda at [third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h:44](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h?l=44&ws=eaeltsin/6692&snapshot=611):9), (lambda at [third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:98](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp?l=98&ws=eaeltsin/6692&snapshot=611):15) &> [third_party/crosstool/v18/llvm_unstable/src/libcxx/include/__type_traits/invoke.h:179](https://cs.corp.google.com/piper///depot/google3/third_party/crosstool/v18/llvm_unstable/src/libcxx/include/__type_traits/invoke.h?l=179&ws=eaeltsin/6692&snapshot=611):25
    #16 0x7f5722f1eeaf in __apply_tuple_impl<(lambda at [third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h:44](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h?l=44&ws=eaeltsin/6692&snapshot=611):9), std::__u::tuple<(lambda at [third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:98](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp?l=98&ws=eaeltsin/6692&snapshot=611):15)> &, 0UL> third_party/crosstool/v18/llvm_unstable/src/libcxx/include/tuple:1380:5
    #17 0x7f5722f1eeaf in apply<(lambda at [third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h:44](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h?l=44&ws=eaeltsin/6692&snapshot=611):9), std::__u::tuple<(lambda at [third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:98](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp?l=98&ws=eaeltsin/6692&snapshot=611):15)> &> third_party/crosstool/v18/llvm_unstable/src/libcxx/include/tuple:1384:5
    #18 0x7f5722f1eeaf in GenericThreadProxy<std::__u::tuple<(lambda at [third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:98](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp?l=98&ws=eaeltsin/6692&snapshot=611):15)> > [third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h:43](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h?l=43&ws=eaeltsin/6692&snapshot=611):5
    #19 0x7f5722f1eeaf in void* llvm::thread::ThreadProxy<std::__u::tuple<clang::clangd::AsyncTaskRunner::runAsync(llvm::Twine const&, llvm::unique_function<void ()>)::$_1>>(void*) [third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h:57](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h?l=57&ws=eaeltsin/6692&snapshot=611):5
    #20 0x55a92182aef0 in asan_thread_start(void*) [third_party/llvm/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp:239](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp?l=239&ws=eaeltsin/6692&snapshot=611):28
    #21 0x7f5726b477da in start_thread (/usr/grte/v5/lib64/libpthread.so.0+0xb7da) (BuildId: b431ea3122d3e21a60bfe317db5010e3)

Thread T49 created by T48 (task:foo.cpp) here:
    #0 0x55a921811821 in pthread_create [third_party/llvm/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp:250](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp?l=250&ws=eaeltsin/6692&snapshot=611):3
    #1 0x7f5736d7451b in __libcpp_thread_create [third_party/crosstool/v18/llvm_unstable/src/libcxx/include/__thread/support/pthread.h:182](https://cs.corp.google.com/piper///depot/google3/third_party/crosstool/v18/llvm_unstable/src/libcxx/include/__thread/support/pthread.h?l=182&ws=eaeltsin/6692&snapshot=611):10
    #2 0x7f5736d7451b in thread<void (std::__u::__async_assoc_state<std::__u::pair<bool, clang::clangd::SymbolSlab>, std::__u::__async_func<(lambda at [third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.h:130](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.h?l=130&ws=eaeltsin/6692&snapshot=611):7), llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>, clang::clangd::Context> >::*)(), std::__u::__async_assoc_state<std::__u::pair<bool, clang::clangd::SymbolSlab>, std::__u::__async_func<(lambda at [third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.h:130](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.h?l=130&ws=eaeltsin/6692&snapshot=611):7), llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>, clang::clangd::Context> > *, 0> [third_party/crosstool/v18/llvm_unstable/src/libcxx/include/__thread/thread.h:219](https://cs.corp.google.com/piper///depot/google3/third_party/crosstool/v18/llvm_unstable/src/libcxx/include/__thread/thread.h?l=219&ws=eaeltsin/6692&snapshot=611):14
    #3 0x7f5736d7451b in std::__u::future<std::__u::pair<bool, clang::clangd::SymbolSlab>> std::__u::__make_async_assoc_state<std::__u::pair<bool, clang::clangd::SymbolSlab>, std::__u::__async_func<std::__u::future<std::__u::pair<bool, clang::clangd::SymbolSlab>> clang::clangd::runAsync<std::__u::pair<bool, clang::clangd::SymbolSlab>>(llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>)::'lambda'(llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>&&, clang::clangd::Context), llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>, clang::clangd::Context>>(std::__u::__async_func<std::__u::future<std::__u::pair<bool, clang::clangd::SymbolSlab>> clang::clangd::runAsync<std::__u::pair<bool, clang::clangd::SymbolSlab>>(llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>)::'lambda'(llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>&&, clang::clangd::Context), llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>, clang::clangd::Context>&&) third_party/crosstool/v18/llvm_unstable/src/libcxx/include/future:1834:3
    #4 0x7f5736d7408e in std::__u::future<std::__u::__invoke_result<__decay(std::__u::pair<bool, clang::clangd::SymbolSlab>), __decay(llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>), __decay(clang::clangd::Context)>::type> std::__u::async<std::__u::future<std::__u::pair<bool, clang::clangd::SymbolSlab>> clang::clangd::runAsync<std::__u::pair<bool, clang::clangd::SymbolSlab>>(llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>)::'lambda'(llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>&&, clang::clangd::Context), llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>, clang::clangd::Context>(std::__u::launch, std::__u::pair<bool, clang::clangd::SymbolSlab>&&, llvm::unique_function<std::__u::pair<bool, clang::clangd::SymbolSlab> ()>&&, clang::clangd::Context&&) third_party/crosstool/v18/llvm_unstable/src/libcxx/include/future:1878:14
    #5 0x7f5736d52c60 in runAsync<std::__u::pair<bool, clang::clangd::SymbolSlab> > [third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.h:128](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.h?l=128&ws=eaeltsin/6692&snapshot=611):10
    #6 0x7f5736d52c60 in startAsyncFuzzyFind [third_party/llvm/llvm-project/clang-tools-extra/clangd/CodeComplete.cpp:1515](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/CodeComplete.cpp?l=1515&ws=eaeltsin/6692&snapshot=611):10
    #7 0x7f5736d52c60 in run [third_party/llvm/llvm-project/clang-tools-extra/clangd/CodeComplete.cpp:1657](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/CodeComplete.cpp?l=1657&ws=eaeltsin/6692&snapshot=611):31
    #8 0x7f5736d52c60 in clang::clangd::codeComplete(llvm::StringRef, clang::clangd::Position, clang::clangd::PreambleData const*, clang::clangd::ParseInputs const&, clang::clangd::CodeCompleteOptions, clang::clangd::SpeculativeFuzzyFind*) [third_party/llvm/llvm-project/clang-tools-extra/clangd/CodeComplete.cpp:2304](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/CodeComplete.cpp?l=2304&ws=eaeltsin/6692&snapshot=611):32
    #9 0x7f5736d365ca in operator() [third_party/llvm/llvm-project/clang-tools-extra/clangd/ClangdServer.cpp:460](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/ClangdServer.cpp?l=460&ws=eaeltsin/6692&snapshot=611):33
    #10 0x7f5736d365ca in void llvm::detail::UniqueFunctionBase<void, llvm::Expected<clang::clangd::InputsAndPreamble>>::CallImpl<clang::clangd::ClangdServer::codeComplete(llvm::StringRef, clang::clangd::Position, clang::clangd::CodeCompleteOptions const&, llvm::unique_function<void (llvm::Expected<clang::clangd::CodeCompleteResult>)>)::$_0>(void*, llvm::Expected<clang::clangd::InputsAndPreamble>&) [third_party/llvm/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:222](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h?l=222&ws=eaeltsin/6692&snapshot=611):12
    #11 0x7f57370b022c in operator() [third_party/llvm/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:387](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h?l=387&ws=eaeltsin/6692&snapshot=611):12
    #12 0x7f57370b022c in operator() [third_party/llvm/llvm-project/clang-tools-extra/clangd/TUScheduler.cpp:1811](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/TUScheduler.cpp?l=1811&ws=eaeltsin/6692&snapshot=611):5
    #13 0x7f57370b022c in void llvm::detail::UniqueFunctionBase<void>::CallImpl<clang::clangd::TUScheduler::runWithPreamble(llvm::StringRef, llvm::StringRef, clang::clangd::TUScheduler::PreambleConsistency, llvm::unique_function<void (llvm::Expected<clang::clangd::InputsAndPreamble>)>)::$_0>(void*) [third_party/llvm/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:222](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h?l=222&ws=eaeltsin/6692&snapshot=611):12
    #14 0x7f5722f1eeaf in operator() [third_party/llvm/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:387](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h?l=387&ws=eaeltsin/6692&snapshot=611):12
    #15 0x7f5722f1eeaf in operator() [third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:101](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp?l=101&ws=eaeltsin/6692&snapshot=611):5
    #16 0x7f5722f1eeaf in operator()<(lambda at [third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:98](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp?l=98&ws=eaeltsin/6692&snapshot=611):15) &> [third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h:45](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h?l=45&ws=eaeltsin/6692&snapshot=611):11
    #17 0x7f5722f1eeaf in __invoke<(lambda at [third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h:44](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h?l=44&ws=eaeltsin/6692&snapshot=611):9), (lambda at [third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:98](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp?l=98&ws=eaeltsin/6692&snapshot=611):15) &> [third_party/crosstool/v18/llvm_unstable/src/libcxx/include/__type_traits/invoke.h:179](https://cs.corp.google.com/piper///depot/google3/third_party/crosstool/v18/llvm_unstable/src/libcxx/include/__type_traits/invoke.h?l=179&ws=eaeltsin/6692&snapshot=611):25
    #18 0x7f5722f1eeaf in __apply_tuple_impl<(lambda at [third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h:44](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h?l=44&ws=eaeltsin/6692&snapshot=611):9), std::__u::tuple<(lambda at [third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:98](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp?l=98&ws=eaeltsin/6692&snapshot=611):15)> &, 0UL> third_party/crosstool/v18/llvm_unstable/src/libcxx/include/tuple:1380:5
    #19 0x7f5722f1eeaf in apply<(lambda at [third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h:44](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h?l=44&ws=eaeltsin/6692&snapshot=611):9), std::__u::tuple<(lambda at [third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:98](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp?l=98&ws=eaeltsin/6692&snapshot=611):15)> &> third_party/crosstool/v18/llvm_unstable/src/libcxx/include/tuple:1384:5
    #20 0x7f5722f1eeaf in GenericThreadProxy<std::__u::tuple<(lambda at [third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:98](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp?l=98&ws=eaeltsin/6692&snapshot=611):15)> > [third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h:43](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h?l=43&ws=eaeltsin/6692&snapshot=611):5
    #21 0x7f5722f1eeaf in void* llvm::thread::ThreadProxy<std::__u::tuple<clang::clangd::AsyncTaskRunner::runAsync(llvm::Twine const&, llvm::unique_function<void ()>)::$_1>>(void*) [third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h:57](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h?l=57&ws=eaeltsin/6692&snapshot=611):5
    #22 0x55a92182aef0 in asan_thread_start(void*) [third_party/llvm/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp:239](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp?l=239&ws=eaeltsin/6692&snapshot=611):28
    #23 0x7f5726b477da in start_thread (/usr/grte/v5/lib64/libpthread.so.0+0xb7da) (BuildId: b431ea3122d3e21a60bfe317db5010e3)

Thread T48 (task:foo.cpp) created by T0 here:
    #0 0x55a921811821 in pthread_create [third_party/llvm/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp:250](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp?l=250&ws=eaeltsin/6692&snapshot=611):3
    #1 0x7f5313cd007a in llvm::llvm_execute_on_thread_impl(void* (*)(void*), void*, std::__u::optional<unsigned int>) third_party/llvm/llvm-project/llvm/lib/Support/Unix/Threading.inc:96:17
    #2 0x7f5722f1e97b in thread<(lambda at [third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:98](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp?l=98&ws=eaeltsin/6692&snapshot=611):15)> [third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h:133](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/llvm/include/llvm/Support/thread.h?l=133&ws=eaeltsin/6692&snapshot=611):12
    #3 0x7f5722f1e97b in clang::clangd::AsyncTaskRunner::runAsync(llvm::Twine const&, llvm::unique_function<void ()>) [third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:107](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/support/Threading.cpp?l=107&ws=eaeltsin/6692&snapshot=611):16
    #4 0x7f573709a752 in clang::clangd::TUScheduler::runWithPreamble(llvm::StringRef, llvm::StringRef, clang::clangd::TUScheduler::PreambleConsistency, llvm::unique_function<void (llvm::Expected<clang::clangd::InputsAndPreamble>)>) [third_party/llvm/llvm-project/clang-tools-extra/clangd/TUScheduler.cpp:1814](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/TUScheduler.cpp?l=1814&ws=eaeltsin/6692&snapshot=611):18
    #5 0x7f5736d1c29b in clang::clangd::ClangdServer::codeComplete(llvm::StringRef, clang::clangd::Position, clang::clangd::CodeCompleteOptions const&, llvm::unique_function<void (llvm::Expected<clang::clangd::CodeCompleteResult>)>) [third_party/llvm/llvm-project/clang-tools-extra/clangd/ClangdServer.cpp:478](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/ClangdServer.cpp?l=478&ws=eaeltsin/6692&snapshot=611):18
    #6 0x7f573a3dd4c5 in clang::clangd::runCodeComplete(clang::clangd::ClangdServer&, llvm::StringRef, clang::clangd::Position, clang::clangd::CodeCompleteOptions) [third_party/llvm/llvm-project/clang-tools-extra/clangd/unittests/SyncAPI.cpp:75](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/unittests/SyncAPI.cpp?l=75&ws=eaeltsin/6692&snapshot=611):10
    #7 0x7f573c00ea8e in clang::clangd::(anonymous namespace)::CompletionTest_EnableSpeculativeIndexRequest_Test::TestBody()::$_0::operator()(llvm::StringRef) const [third_party/llvm/llvm-project/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp:2934](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp?l=2934&ws=eaeltsin/6692&snapshot=611):25
    #8 0x7f573c00e0f0 in clang::clangd::(anonymous namespace)::CompletionTest_EnableSpeculativeIndexRequest_Test::TestBody() [third_party/llvm/llvm-project/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp:2949](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp?l=2949&ws=eaeltsin/6692&snapshot=611):3
    #9 0x7f53145ac861 in HandleExceptionsInMethodIfSupported<testing::Test, void> third_party/llvm/llvm-project/third-party/unittest/googletest/src/gtest.cc
    #10 0x7f53145ac861 in testing::Test::Run() [third_party/llvm/llvm-project/third-party/unittest/googletest/src/gtest.cc:2687](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/third-party/unittest/googletest/src/gtest.cc?l=2687&ws=eaeltsin/6692&snapshot=611):5
    #11 0x7f53145ae92c in testing::TestInfo::Run() [third_party/llvm/llvm-project/third-party/unittest/googletest/src/gtest.cc:2836](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/third-party/unittest/googletest/src/gtest.cc?l=2836&ws=eaeltsin/6692&snapshot=611):11
    #12 0x7f53145b01e0 in testing::TestSuite::Run() [third_party/llvm/llvm-project/third-party/unittest/googletest/src/gtest.cc:3015](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/third-party/unittest/googletest/src/gtest.cc?l=3015&ws=eaeltsin/6692&snapshot=611):30
    #13 0x7f53145cc9cf in testing::internal::UnitTestImpl::RunAllTests() [third_party/llvm/llvm-project/third-party/unittest/googletest/src/gtest.cc:5920](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/third-party/unittest/googletest/src/gtest.cc?l=5920&ws=eaeltsin/6692&snapshot=611):44
    #14 0x7f53145cc23d in bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) third_party/llvm/llvm-project/third-party/unittest/googletest/src/gtest.cc
    #15 0x7f53145cc01d in testing::UnitTest::Run() [third_party/llvm/llvm-project/third-party/unittest/googletest/src/gtest.cc:5484](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/third-party/unittest/googletest/src/gtest.cc?l=5484&ws=eaeltsin/6692&snapshot=611):10
    #16 0x7f531522374b in RUN_ALL_TESTS [third_party/llvm/llvm-project/third-party/unittest/googletest/include/gtest/gtest.h:2317](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/third-party/unittest/googletest/include/gtest/gtest.h?l=2317&ws=eaeltsin/6692&snapshot=611):73
    #17 0x7f531522374b in main [third_party/llvm/llvm-project/third-party/unittest/UnitTestMain/TestMain.cpp:75](https://cs.corp.google.com/piper///depot/google3/third_party/llvm/llvm-project/third-party/unittest/UnitTestMain/TestMain.cpp?l=75&ws=eaeltsin/6692&snapshot=611):10
    #18 0x7f535c9f73d3 in __libc_start_main (/usr/grte/v5/lib64/libc.so.6+0x613d3) (BuildId: 9a996398ce14a94560b0c642eb4f6e94)
    #19 0x55a92178c929 in _start /usr/grte/v5/debug-src/src/csu/../sysdeps/x86_64/start.S:120

kadircet added a commit to kadircet/llvm-project that referenced this pull request Mar 6, 2025
We started seeing some use-after-frees starting with llvm#125433.

This patch ensures we explicitly block for the async task, if there's
one, before destructing std::future, independent of the stdlib
implementation.
kadircet added a commit that referenced this pull request Mar 6, 2025
We started seeing some use-after-frees starting with
#125433.

This patch ensures we explicitly block for the async task, if there's
one, before destructing `std::future`, independent of the stdlib
implementation.
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Mar 6, 2025
…077)

We started seeing some use-after-frees starting with
llvm/llvm-project#125433.

This patch ensures we explicitly block for the async task, if there's
one, before destructing `std::future`, independent of the stdlib
implementation.
@asmok-g
Copy link

asmok-g commented Mar 6, 2025

There are other instances to the problem like the one kadircet described in clangd. Sjould we consider reverting the patch ?

@philnik777
Copy link
Contributor Author

@kadircet @asmok-g I've just uploaded #130145, which I believe addresses your problems. Could you check to make sure I'm not fixing something unrelated?

@kadircet
Copy link
Member

hi @philnik777, I guess we're aligned on this being a regression until it's fixed forward and it has been ~2 weeks without it. WDYT about reverting this change and landing it with a fix going forward to minimize the bad commit range ?

@philnik777
Copy link
Contributor Author

@kadircet Yeah, feel free to revert.

@ldionne
Copy link
Member

ldionne commented Mar 18, 2025

@kadircet Let's be careful to re-open any closed bugs when a patch is reverted like this :) Otherwise the bug will be forgotten!

jph-13 pushed a commit to jph-13/llvm-project that referenced this pull request Mar 21, 2025
We started seeing some use-after-frees starting with
llvm#125433.

This patch ensures we explicitly block for the async task, if there's
one, before destructing `std::future`, independent of the stdlib
implementation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

std::async in future does not throw system_error as required (libc++)
7 participants