Issue 202989
Summary [clangd][modules] Assertion `Node.getKeyData() == Node.getValue().URI.data()' failed.` when `-fmodules`is enabled, `didopen` a C file and --background-index is enabled
Labels
Assignees
Reporter hongtaihu
    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 <stddef.h>
```

After debugging, it is found that apart from 
```c
#include <stddef.h>
```
,
```c
#include <stddef.h>
#include <stdalign.h>
#include <stdnoreturn.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <uchar.h>
```
can be used to trigger as well.

But 
```
<math.h>
```
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) <REPO_ROOT>/tmp/llvm-project-main-20260608-latest/llvm/lib/Support/Unix/Signals.inc:885:3
 #1 0x00005fa36e5e135c llvm::sys::RunSignalHandlers() <REPO_ROOT>/tmp/llvm-project-main-20260608-latest/llvm/lib/Support/Signals.cpp:108:20
 #2 0x00005fa36e5e1bd1 SignalHandler(int, siginfo_t*, void*) <REPO_ROOT>/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 (<REPO_ROOT>/tmp/build-assert-clangd-main-20260608-latest/bin/clangd+0x1ce411f)
#12 0x00005fa37025e998 std::__shared_ptr<clang::FrontendOptions, (__gnu_cxx::_Lock_policy)2>::get() const /usr/include/c++/13/bits/shared_ptr_base.h:1666:16
#13 0x00005fa37025e998 std::__shared_ptr_access<clang::FrontendOptions, (__gnu_cxx::_Lock_policy)2, false, false>::_M_get() const /usr/include/c++/13/bits/shared_ptr_base.h:1363:69
#14 0x00005fa37025e998 std::__shared_ptr_access<clang::FrontendOptions, (__gnu_cxx::_Lock_policy)2, false, false>::operator*() const /usr/include/c++/13/bits/shared_ptr_base.h:1349:2
#15 0x00005fa37025e998 clang::CompilerInvocation::getFrontendOpts() <REPO_ROOT>/tmp/llvm-project-main-20260608-latest/clang/include/clang/Frontend/CompilerInvocation.h:277:48
#16 0x00005fa37025e998 clang::CompilerInstance::getFrontendOpts() <REPO_ROOT>/tmp/llvm-project-main-20260608-latest/clang/include/clang/Frontend/CompilerInstance.h:314:39
#17 0x00005fa37025e998 clang::FrontendAction::EndSourceFile() <REPO_ROOT>/tmp/llvm-project-main-20260608-latest/clang/lib/Frontend/FrontendAction.cpp:1382:40
#18 0x00005fa36fe1bc9f std::enable_if<__and_v<std::__not_<std::is_same<std::optional<clang::tooling::CompileCommand>, std::remove_cv<std::remove_reference<clang::tooling::CompileCommand&>::type>::type>>, std::__not_<std::__and_<std::is_scalar<clang::tooling::CompileCommand>, std::is_same<clang::tooling::CompileCommand, std::decay<clang::tooling::CompileCommand&>::type>>>, std::is_constructible<clang::tooling::CompileCommand, clang::tooling::CompileCommand&>, std::is_assignable<clang::tooling::CompileCommand&, clang::tooling::CompileCommand&>>, std::optional<clang::tooling::CompileCommand>&>::type std::optional<clang::tooling::CompileCommand>::operator=<clang::tooling::CompileCommand&>(clang::tooling::CompileCommand&) /usr/include/c++/13/optional:852:4
#19 0x00005fa36fe1bc9f clang::clangd::BackgroundIndex::index(clang::tooling::CompileCommand) <REPO_ROOT>/tmp/llvm-project-main-20260608-latest/clang-tools-extra/clangd/index/Background.cpp:327:22
#20 0x00005fa36fe1c997 std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::~basic_string() /usr/include/c++/13/bits/basic_string.h:804:19
#21 0x00005fa36fe1c997 clang::tooling::CompileCommand::~CompileCommand() <REPO_ROOT>/tmp/llvm-project-main-20260608-latest/clang/include/clang/Tooling/CompilationDatabase.h:44:8
#22 0x00005fa36fe1c997 clang::clangd::BackgroundIndex::indexFileTask(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)::'lambda'()::operator()() const <REPO_ROOT>/tmp/llvm-project-main-20260608-latest/clang-tools-extra/clangd/index/Background.cpp:168:43
#23 0x00005fa36fe27bfe std::_Optional_base_impl<clang::clangd::BackgroundQueue::Task, std::_Optional_base<clang::clangd::BackgroundQueue::Task, false, false>>::_M_get() /usr/include/c++/13/optional:479:2
#24 0x00005fa36fe27bfe std::optional<clang::clangd::BackgroundQueue::Task>::operator->() /usr/include/c++/13/optional:968:45
#25 0x00005fa36fe27bfe clang::clangd::BackgroundQueue::work(std::function<void ()>) <REPO_ROOT>/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<void ()>::~function() /usr/include/c++/13/bits/std_function.h:334:11
#28 0x00005fa36fe178cb operator() <REPO_ROOT>/tmp/llvm-project-main-20260608-latest/clang-tools-extra/clangd/index/Background.cpp:114:37
#29 0x00005fa36fe178cb void llvm::detail::UniqueFunctionBase<void>::CallImpl<clang::clangd::BackgroundIndex::BackgroundIndex(clang::clangd::ThreadsafeFS const&, clang::clangd::GlobalCompilationDatabase const&, llvm::unique_function<clang::clangd::BackgroundIndexStorage* (llvm::StringRef)>, clang::clangd::BackgroundIndex::Options)::'lambda'()>(void*) <REPO_ROOT>/tmp/llvm-project-main-20260608-latest/llvm/include/llvm/ADT/FunctionExtras.h:211:16
#30 0x00005fa36feba16e llvm::detail::UniqueFunctionBase<void>::operator=(llvm::detail::UniqueFunctionBase<void>&&) <REPO_ROOT>/tmp/llvm-project-main-20260608-latest/llvm/include/llvm/ADT/FunctionExtras.h:326:5
#31 0x00005fa36feba16e llvm::detail::UniqueFunctionBase<void>::operator=(llvm::detail::UniqueFunctionBase<void>&&) <REPO_ROOT>/tmp/llvm-project-main-20260608-latest/llvm/include/llvm/ADT/FunctionExtras.h:318:23
#32 0x00005fa36feba16e llvm::unique_function<void ()>::operator=(llvm::unique_function<void ()>&&) <REPO_ROOT>/tmp/llvm-project-main-20260608-latest/llvm/include/llvm/ADT/FunctionExtras.h:349:20
#33 0x00005fa36feba16e operator() <REPO_ROOT>/tmp/llvm-project-main-20260608-latest/clang-tools-extra/clangd/support/Threading.cpp:103:14
#34 0x00005fa36feba16e operator()<clang::clangd::AsyncTaskRunner::runAsync(const llvm::Twine&, llvm::unique_function<void()>)::<lambda()>&> <REPO_ROOT>/tmp/llvm-project-main-20260608-latest/llvm/include/llvm/Support/thread.h:46:16
#35 0x00005fa36feba16e __invoke_impl<void, llvm::thread::GenericThreadProxy<std::tuple<clang::clangd::AsyncTaskRunner::runAsync(const llvm::Twine&, llvm::unique_function<void()>)::<lambda()> > >(void*)::<lambda(auto:5&&, auto:6&& ...)>, clang::clangd::AsyncTaskRunner::runAsync(const llvm::Twine&, llvm::unique_function<void()>)::<lambda()>&> /usr/include/c++/13/bits/invoke.h:61:36
#36 0x00005fa36feba16e __invoke<llvm::thread::GenericThreadProxy<std::tuple<clang::clangd::AsyncTaskRunner::runAsync(const llvm::Twine&, llvm::unique_function<void()>)::<lambda()> > >(void*)::<lambda(auto:5&&, auto:6&& ...)>, clang::clangd::AsyncTaskRunner::runAsync(const llvm::Twine&, llvm::unique_function<void()>)::<lambda()>&> /usr/include/c++/13/bits/invoke.h:96:40
#37 0x00005fa36feba16e __apply_impl<llvm::thread::GenericThreadProxy<std::tuple<clang::clangd::AsyncTaskRunner::runAsync(const llvm::Twine&, llvm::unique_function<void()>)::<lambda()> > >(void*)::<lambda(auto:5&&, auto:6&& ...)>, std::tuple<clang::clangd::AsyncTaskRunner::runAsync(const llvm::Twine&, llvm::unique_function<void()>)::<lambda()> >&, 0> /usr/include/c++/13/tuple:2302:27
#38 0x00005fa36feba16e apply<llvm::thread::GenericThreadProxy<std::tuple<clang::clangd::AsyncTaskRunner::runAsync(const llvm::Twine&, llvm::unique_function<void()>)::<lambda()> > >(void*)::<lambda(auto:5&&, auto:6&& ...)>, std::tuple<clang::clangd::AsyncTaskRunner::runAsync(const llvm::Twine&, llvm::unique_function<void()>)::<lambda()> >&> /usr/include/c++/13/tuple:2313:31
#39 0x00005fa36feba16e GenericThreadProxy<std::tuple<clang::clangd::AsyncTaskRunner::runAsync(const llvm::Twine&, llvm::unique_function<void()>)::<lambda()> > > <REPO_ROOT>/tmp/llvm-project-main-20260608-latest/llvm/include/llvm/Support/thread.h:44:15
#40 0x00005fa36feba16e void* llvm::thread::ThreadProxy<std::tuple<clang::clangd::AsyncTaskRunner::runAsync(llvm::Twine const&, llvm::unique_function<void ()>)::'lambda0'()>>(void*) <REPO_ROOT>/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
<REPO_ROOT>/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
```

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to