[clangd][clang] clangd completion crashes with assertion `VDecl->isLinkageValid()` in `Sema::DeduceVariableDeclarationType`
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
This is generated by a fuzzer.
I could not reproduce it by invoking the Clang frontend directly.
source code
```cxx
auto a = [] {
```
requests
```
initialize -> initialized -> didOpen -> textDocument/completion->shutdown -> exit
```
location(0-based)
```
- line = 1
- character = 0
```
The completion request is issued at the beginning of the blank second line after the incomplete lambda introducer.
backtrace
```
I[01:17:18.628] Indexing c++17 standard library in the context of /harness/cases/staging/CASE-20260530-085/workspace/cxx2a-template-lambdas.cpp
I[01:17:18.636] --> textDocument/publishDiagnostics
I[01:17:18.958] <-- textDocument/completion(2)
I[01:17:18.966] Code complete: sema context Statement, query scopes [] (AnyScope=true), expected type
clangd: /tmp/llvm-project-main-20260504/clang/lib/Sema/SemaDecl.cpp:13448: bool clang::Sema::DeduceVariableDeclarationType(clang::VarDecl*, bool, clang::Expr*): Assertion `VDecl->isLinkageValid()' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0. parser at end of file
I[01:17:19.018] <-- shutdown(1000)
I[01:17:19.019] --> reply:shutdown(1000) 0 ms
I[01:17:19.079] <-- exit
I[01:17:19.079] LSP finished, exiting with status 0
I[01:17:19.403] Indexed c++17 standard library (incomplete due to errors): 13460 symbols, 2103 filtered
#0 0x000056e56a33d8f2 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /tmp/llvm-project-main-20260504/llvm/lib/Support/Unix/Signals.inc:884:3
#1 0x000056e56a33a66c llvm::sys::RunSignalHandlers() /tmp/llvm-project-main-20260504/llvm/lib/Support/Signals.cpp:108:20
#2 0x000056e56a33aee1 SignalHandler(int, siginfo_t*, void*) /tmp/llvm-project-main-20260504/llvm/lib/Support/Unix/Signals.inc:448:14
#3 0x00007a361e045330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#4 0x00007a361e09eb2c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x00007a361e09eb2c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#6 0x00007a361e09eb2c pthread_kill ./nptl/pthread_kill.c:89:10
#7 0x00007a361e04527e raise ./signal/../sysdeps/posix/raise.c:27:6
#8 0x00007a361e0288ff abort ./stdlib/abort.c:81:7
#9 0x00007a361e02881b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x00007a361e03b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#11 0x000056e56b1e4191 clang::Sema::DeduceVariableDeclarationType(clang::VarDecl*, bool, clang::Expr*) /tmp/llvm-project-main-20260504/clang/lib/Sema/SemaDecl.cpp:13438:3
#12 0x000056e56b1fb4ab clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) /tmp/llvm-project-main-20260504/clang/lib/Sema/SemaDecl.cpp:13949:5
#13 0x000056e56c1e9aeb clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) /tmp/llvm-project-main-20260504/clang/lib/Parse/ParseDecl.cpp:2666:5
#14 0x000056e56c1fbb02 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) /tmp/llvm-project-main-20260504/clang/lib/Parse/ParseDecl.cpp:2382:3
#15 0x000056e56c1bd1f9 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) /tmp/llvm-project-main-20260504/clang/lib/Parse/Parser.cpp:1153:73
#16 0x000056e56c1bda7f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) /tmp/llvm-project-main-20260504/clang/lib/Parse/Parser.cpp:1175:42
#17 0x000056e56c1c4571 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) /tmp/llvm-project-main-20260504/clang/lib/Parse/Parser.cpp:1003:50
#18 0x000056e56c1c6237 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) /tmp/llvm-project-main-20260504/clang/lib/Parse/Parser.cpp:711:36
#19 0x000056e56c1c66d3 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) /tmp/llvm-project-main-20260504/clang/lib/Parse/Parser.cpp:608:32
#20 0x000056e56c1aaaaa clang::ParseAST(clang::Sema&, bool, bool) /tmp/llvm-project-main-20260504/clang/lib/Parse/ParseAST.cpp:169:69
#21 0x000056e56bfa46e7 clang::FrontendAction::Execute() /tmp/llvm-project-main-20260504/clang/lib/Frontend/FrontendAction.cpp:1346:38
#22 0x000056e56b80383c llvm::Error::getPtr() const /tmp/llvm-project-main-20260504/llvm/include/llvm/Support/Error.h:278:51
#23 0x000056e56b80383c llvm::Error::operator bool() /tmp/llvm-project-main-20260504/llvm/include/llvm/Support/Error.h:241:22
#24 0x000056e56b80383c clang::clangd::(anonymous namespace)::semaCodeComplete(std::unique_ptr>, clang::CodeCompleteOptions const&, clang::clangd::(anonymous namespace)::SemaCompleteInput const&, clang::clangd::IncludeStructure*) (.isra.0) /tmp/llvm-project-main-20260504/clang-tools-extra/clangd/CodeComplete.cpp:1464:41
#25 0x000056e56b81489c std::unique_ptr>::~unique_ptr() /usr/include/c++/13/bits/unique_ptr.h:403:12
#26 0x000056e56b81489c run /tmp/llvm-project-main-20260504/clang-tools-extra/clangd/CodeComplete.cpp:1727:21
#27 0x000056e56b81489c clang::clangd::codeComplete(llvm::StringRef, clang::clangd::Position, clang::clangd::PreambleData const*, clang::clangd::ParseInputs const&, clang::clangd::CodeCompleteOptions, clang::clangd::SpeculativeFuzzyFind*) /tmp/llvm-project-main-20260504/clang-tools-extra/clangd/CodeComplete.cpp:2335:48
#28 0x000056e56b7e1c56 std::function::~function() /usr/include/c++/13/bits/std_function.h:334:11
#29 0x000056e56b7e1c56 clang::clangd::CodeCompleteOptions::~CodeCompleteOptions() /tmp/llvm-project-main-20260504/clang-tools-extra/clangd/CodeComplete.h:43:8
#30 0x000056e56b7e1c56 clang::clangd::ClangdServer::codeComplete(llvm::StringRef, clang::clangd::Position, clang::clangd::CodeCompleteOptions const&, llvm::unique_function)>)::'lambda'(llvm::Expected)::operator()(llvm::Expected) /tmp/llvm-project-main-20260504/clang-tools-extra/clangd/ClangdServer.cpp:469:50
#31 0x000056e56b7e26e3 llvm::Expected::assertIsChecked() const /tmp/llvm-project-main-20260504/llvm/include/llvm/Support/Error.h:729:9
#32 0x000056e56b7e26e3 llvm::Expected::~Expected() /tmp/llvm-project-main-20260504/llvm/include/llvm/Support/Error.h:566:20
#33 0x000056e56b7e26e3 void llvm::detail::UniqueFunctionBase>::CallImpl)>)::'lambda'(llvm::Expected)>(void*, llvm::Expected&) /tmp/llvm-project-main-20260504/llvm/include/llvm/ADT/FunctionExtras.h:212:16
#34 0x000056e56ba292eb llvm::Expected::assertIsChecked() const /tmp/llvm-project-main-20260504/llvm/include/llvm/Support/Error.h:729:9
#35 0x000056e56ba292eb llvm::Expected::~Expected() /tmp/llvm-project-main-20260504/llvm/include/llvm/Support/Error.h:566:20
#36 0x000056e56ba292eb clang::clangd::TUScheduler::runWithPreamble(llvm::StringRef, llvm::StringRef, clang::clangd::TUScheduler::PreambleConsistency, llvm::unique_function)>)::'lambda'()::operator()() /tmp/llvm-project-main-20260504/clang-tools-extra/clangd/TUScheduler.cpp:1810:11
#37 0x000056e56bc07b6e llvm::detail::UniqueFunctionBase::operator=(llvm::detail::UniqueFunctionBase&&) /tmp/llvm-project-main-20260504/llvm/include/llvm/ADT/FunctionExtras.h:329:5
#38 0x000056e56bc07b6e llvm::detail::UniqueFunctionBase::operator=(llvm::detail::UniqueFunctionBase&&) /tmp/llvm-project-main-20260504/llvm/include/llvm/ADT/FunctionExtras.h:321:23
#39 0x000056e56bc07b6e llvm::unique_function::operator=(llvm::unique_function&&) /tmp/llvm-project-main-20260504/llvm/include/llvm/ADT/FunctionExtras.h:352:20
#40 0x000056e56bc07b6e operator() /tmp/llvm-project-main-20260504/clang-tools-extra/clangd/support/Threading.cpp:103:14
#41 0x000056e56bc07b6e operator())::&> /tmp/llvm-project-main-20260504/llvm/include/llvm/Support/thread.h:46:16
#42 0x000056e56bc07b6e __invoke_impl):: > >(void*)::, clang::clangd::AsyncTaskRunner::runAsync(const llvm::Twine&, llvm::unique_function)::&> /usr/include/c++/13/bits/invoke.h:61:36
#43 0x000056e56bc07b6e __invoke):: > >(void*)::, clang::clangd::AsyncTaskRunner::runAsync(const llvm::Twine&, llvm::unique_function)::&> /usr/include/c++/13/bits/invoke.h:96:40
#44 0x000056e56bc07b6e __apply_impl):: > >(void*)::, std::tuple):: >&, 0> /usr/include/c++/13/tuple:2302:27
#45 0x000056e56bc07b6e apply):: > >(void*)::, std::tuple):: >&> /usr/include/c++/13/tuple:2313:31
#46 0x000056e56bc07b6e GenericThreadProxy):: > > /tmp/llvm-project-main-20260504/llvm/include/llvm/Support/thread.h:44:15
#47 0x000056e56bc07b6e void* llvm::thread::ThreadProxy)::'lambda0'()>>(void*) /tmp/llvm-project-main-20260504/llvm/include/llvm/Support/thread.h:62:36
#48 0x00007a361e09caa4 start_thread ./nptl/pthread_create.c:447:8
#49 0x00007a361e129c6c clone3 ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:80:0
Signalled during preamble action: CodeComplete
Filename: cxx2a-template-lambdas.cpp
Directory: /harness/cases/staging/CASE-20260530-085/workspace
Command Line: /usr/lib/llvm-18/bin/clang -resource-dir=/tmp/build-assert-clangd-main-20260506/lib/clang/23 -- /harness/cases/staging/CASE-20260530-085/workspace/cxx2a-template-lambdas.cpp
```
Contributor guide
Assessment
This issue has not been assessed yet.