llvm / llvm/llvm-project

[clangd][modules] Assertion `Node.getKeyData() == Node.getValue().URI.data()' failed.` when `-fmodules`is enabled, `didopen` a C file and --background-index is enabled

Open
#202,989 2 comments 0 reactions 0 assignees View on GitHub
clang:modules clangd crash generated by fuzzer
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

This input is generated by a fuzzer.

The source code is very simple:

requests:
```
initialize -> initialized -> didOpen-> shutdown -> exit
```

using `clangd -check` cannot reproduce this issue on my computer.

example.c:
```c
#include
```

After debugging, it is found that apart from
```c
#include
```
,
```c
#include
#include
#include
#include
#include
#include
#include
#include
```
can be used to trigger as well.

But
```

```
cannot do it.
Assertion:
```
clang-tools-extra/clangd/index/IndexAction.cpp:190: virtual void clang::clangd::{anonymous}::IndexAction::EndSourceFileAction(): Assertion `Node.getKeyData() == Node.getValue().URI.data()' failed.
```

stacktrace:
```
#0 0x00005fa36e5e45e2 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /tmp/llvm-project-main-20260608-latest/llvm/lib/Support/Unix/Signals.inc:885:3
#1 0x00005fa36e5e135c llvm::sys::RunSignalHandlers() /tmp/llvm-project-main-20260608-latest/llvm/lib/Support/Signals.cpp:108:20
#2 0x00005fa36e5e1bd1 SignalHandler(int, siginfo_t*, void*) /tmp/llvm-project-main-20260608-latest/llvm/lib/Support/Unix/Signals.inc:448:14
#3 0x00007dce71a45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#4 0x00007dce71a9eb2c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x00007dce71a9eb2c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#6 0x00007dce71a9eb2c pthread_kill ./nptl/pthread_kill.c:89:10
#7 0x00007dce71a4527e raise ./signal/../sysdeps/posix/raise.c:27:6
#8 0x00007dce71a288ff abort ./stdlib/abort.c:81:7
#9 0x00007dce71a2881b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x00007dce71a3b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#11 0x00005fa36fe3d11f (/tmp/build-assert-clangd-main-20260608-latest/bin/clangd+0x1ce411f)
#12 0x00005fa37025e998 std::__shared_ptr::get() const /usr/include/c++/13/bits/shared_ptr_base.h:1666:16
#13 0x00005fa37025e998 std::__shared_ptr_access::_M_get() const /usr/include/c++/13/bits/shared_ptr_base.h:1363:69
#14 0x00005fa37025e998 std::__shared_ptr_access::operator*() const /usr/include/c++/13/bits/shared_ptr_base.h:1349:2
#15 0x00005fa37025e998 clang::CompilerInvocation::getFrontendOpts() /tmp/llvm-project-main-20260608-latest/clang/include/clang/Frontend/CompilerInvocation.h:277:48
#16 0x00005fa37025e998 clang::CompilerInstance::getFrontendOpts() /tmp/llvm-project-main-20260608-latest/clang/include/clang/Frontend/CompilerInstance.h:314:39
#17 0x00005fa37025e998 clang::FrontendAction::EndSourceFile() /tmp/llvm-project-main-20260608-latest/clang/lib/Frontend/FrontendAction.cpp:1382:40
#18 0x00005fa36fe1bc9f std::enable_if<__and_v, std::remove_cv::type>::type>>, std::__not_, std::is_same::type>>>, std::is_constructible, std::is_assignable>, std::optional&>::type std::optional::operator=(clang::tooling::CompileCommand&) /usr/include/c++/13/optional:852:4
#19 0x00005fa36fe1bc9f clang::clangd::BackgroundIndex::index(clang::tooling::CompileCommand) /tmp/llvm-project-main-20260608-latest/clang-tools-extra/clangd/index/Background.cpp:327:22
#20 0x00005fa36fe1c997 std::__cxx11::basic_string, std::allocator>::~basic_string() /usr/include/c++/13/bits/basic_string.h:804:19
#21 0x00005fa36fe1c997 clang::tooling::CompileCommand::~CompileCommand() /tmp/llvm-project-main-20260608-latest/clang/include/clang/Tooling/CompilationDatabase.h:44:8
#22 0x00005fa36fe1c997 clang::clangd::BackgroundIndex::indexFileTask(std::__cxx11::basic_string, std::allocator>)::'lambda'()::operator()() const /tmp/llvm-project-main-20260608-latest/clang-tools-extra/clangd/index/Background.cpp:168:43
#23 0x00005fa36fe27bfe std::_Optional_base_impl>::_M_get() /usr/include/c++/13/optional:479:2
#24 0x00005fa36fe27bfe std::optional::operator->() /usr/include/c++/13/optional:968:45
#25 0x00005fa36fe27bfe clang::clangd::BackgroundQueue::work(std::function) /tmp/llvm-project-main-20260608-latest/clang-tools-extra/clangd/index/BackgroundQueue.cpp:44:13
#26 0x00005fa36fe178cb std::_Function_base::~_Function_base() /usr/include/c++/13/bits/std_function.h:243:11
#27 0x00005fa36fe178cb std::function::~function() /usr/include/c++/13/bits/std_function.h:334:11
#28 0x00005fa36fe178cb operator() /tmp/llvm-project-main-20260608-latest/clang-tools-extra/clangd/index/Background.cpp:114:37
#29 0x00005fa36fe178cb void llvm::detail::UniqueFunctionBase::CallImpl, clang::clangd::BackgroundIndex::Options)::'lambda'()>(void*) /tmp/llvm-project-main-20260608-latest/llvm/include/llvm/ADT/FunctionExtras.h:211:16
#30 0x00005fa36feba16e llvm::detail::UniqueFunctionBase::operator=(llvm::detail::UniqueFunctionBase&&) /tmp/llvm-project-main-20260608-latest/llvm/include/llvm/ADT/FunctionExtras.h:326:5
#31 0x00005fa36feba16e llvm::detail::UniqueFunctionBase::operator=(llvm::detail::UniqueFunctionBase&&) /tmp/llvm-project-main-20260608-latest/llvm/include/llvm/ADT/FunctionExtras.h:318:23
#32 0x00005fa36feba16e llvm::unique_function::operator=(llvm::unique_function&&) /tmp/llvm-project-main-20260608-latest/llvm/include/llvm/ADT/FunctionExtras.h:349:20
#33 0x00005fa36feba16e operator() /tmp/llvm-project-main-20260608-latest/clang-tools-extra/clangd/support/Threading.cpp:103:14
#34 0x00005fa36feba16e operator())::&> /tmp/llvm-project-main-20260608-latest/llvm/include/llvm/Support/thread.h:46:16
#35 0x00005fa36feba16e __invoke_impl):: > >(void*)::, clang::clangd::AsyncTaskRunner::runAsync(const llvm::Twine&, llvm::unique_function)::&> /usr/include/c++/13/bits/invoke.h:61:36
#36 0x00005fa36feba16e __invoke):: > >(void*)::, clang::clangd::AsyncTaskRunner::runAsync(const llvm::Twine&, llvm::unique_function)::&> /usr/include/c++/13/bits/invoke.h:96:40
#37 0x00005fa36feba16e __apply_impl):: > >(void*)::, std::tuple):: >&, 0> /usr/include/c++/13/tuple:2302:27
#38 0x00005fa36feba16e apply):: > >(void*)::, std::tuple):: >&> /usr/include/c++/13/tuple:2313:31
#39 0x00005fa36feba16e GenericThreadProxy):: > > /tmp/llvm-project-main-20260608-latest/llvm/include/llvm/Support/thread.h:44:15
#40 0x00005fa36feba16e void* llvm::thread::ThreadProxy)::'lambda0'()>>(void*) /tmp/llvm-project-main-20260608-latest/llvm/include/llvm/Support/thread.h:62:36
#41 0x00007dce71a9caa4 start_thread ./nptl/pthread_create.c:447:8
#42 0x00007dce71b29c6c clone3 ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:80:0
/harness/scripts/run_clangd_didopen_workspace.sh: line 117: 13383 Done { emit_lsp "$INIT"; emit_lsp "$INITIALIZED"; emit_lsp "$DIDOPEN"; sleep "$DIDOPEN_WAIT_SECS"; if [[ -n "$POST_OPEN" ]]; then
emit_lsp "$POST_OPEN";
```

the command in the .json:
```
-fmodules -fsyntax-only
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.