[clangd][ObjC][module] Assertion `getNumModuleIdentifiers(Imported) == IdentifierLocs.size()' failed.` on `didopen` request
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
This input is generated by a fuzzer.
```objective-c
@import _Builtin_intrinsics.a
```
use the command:
```
- fmodules
- target aarch64-unknown-unknown
- std=c++26
-x objective-c
```
However, if
```
- target aarch64-unknown-unknown
```
or
```
- std=c++26
```
is disabled, the issue falls to https://github.com/llvm/llvm-project/issues/198851.
The background index needs to be enabled.
requests:
```
initialize -> initialized -> didOpen -> shutdown -> exit
```
stacktrace:
```
#0 0x00005b9d8e04c5e2 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /tmp/llvm-project-main-20260608-latest/llvm/lib/Support/Unix/Signals.inc:885:3
#1 0x00005b9d8e04935c llvm::sys::RunSignalHandlers() /tmp/llvm-project-main-20260608-latest/llvm/lib/Support/Signals.cpp:108:20
#2 0x00005b9d8e049bd1 SignalHandler(int, siginfo_t*, void*) /tmp/llvm-project-main-20260608-latest/llvm/lib/Support/Unix/Signals.inc:448:14
#3 0x0000743be1245330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#4 0x0000743be129eb2c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x0000743be129eb2c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#6 0x0000743be129eb2c pthread_kill ./nptl/pthread_kill.c:89:10
#7 0x0000743be124527e raise ./signal/../sysdeps/posix/raise.c:27:6
#8 0x0000743be12288ff abort ./stdlib/abort.c:81:7
#9 0x0000743be122881b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x0000743be123b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#11 0x00005b9d8e1c753a (/tmp/build-assert-clangd-main-20260608-latest/bin/clangd+0x60653a)
#12 0x00005b9d8e1c75e3 clang::ImportDecl::Create(clang::ASTContext&, clang::DeclContext*, clang::SourceLocation, clang::Module*, llvm::ArrayRef) /tmp/llvm-project-main-20260608-latest/clang/lib/AST/Decl.cpp:6078:1
#13 0x00005b9d8e9945bc clang::Sema::ActOnModuleImport(clang::SourceLocation, clang::SourceLocation, clang::SourceLocation, clang::Module*, llvm::ArrayRef) /tmp/llvm-project-main-20260608-latest/clang/lib/Sema/SemaModule.cpp:688:22
#14 0x00005b9d8e9952f8 clang::Sema::ActOnModuleImport(clang::SourceLocation, clang::SourceLocation, clang::SourceLocation, llvm::ArrayRef, bool) /tmp/llvm-project-main-20260608-latest/clang/lib/Sema/SemaModule.cpp:617:27
#15 0x00005b9d8fee4e4a clang::Parser::ParseModuleImport(clang::SourceLocation, clang::Sema::ModuleImportState&) /tmp/llvm-project-main-20260608-latest/clang/lib/Parse/Parser.cpp:2528:39
#16 0x00005b9d8ff8b7d7 clang::Parser::ParseObjCAtDirectives(clang::ParsedAttributes&, clang::ParsedAttributes&) /tmp/llvm-project-main-20260608-latest/clang/lib/Parse/ParseObjc.cpp:93:37
#17 0x00005b9d8fee8ed2 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) /tmp/llvm-project-main-20260608-latest/clang/lib/Parse/Parser.cpp:859:33
#18 0x00005b9d8feea827 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) /tmp/llvm-project-main-20260608-latest/clang/lib/Parse/Parser.cpp:711:36
#19 0x00005b9d8feeacc3 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) /tmp/llvm-project-main-20260608-latest/clang/lib/Parse/Parser.cpp:608:32
#20 0x00005b9d8fecf0ea clang::ParseAST(clang::Sema&, bool, bool) /tmp/llvm-project-main-20260608-latest/clang/lib/Parse/ParseAST.cpp:169:69
#21 0x00005b9d8fcc5a41 clang::FrontendAction::Execute() /tmp/llvm-project-main-20260608-latest/clang/lib/Frontend/FrontendAction.cpp:1346:38
#22 0x00005b9d8f883c66 llvm::Error::getPtr() const /tmp/llvm-project-main-20260608-latest/llvm/include/llvm/Support/Error.h:278:51
#23 0x00005b9d8f883c66 llvm::Error::operator bool() /tmp/llvm-project-main-20260608-latest/llvm/include/llvm/Support/Error.h:241:22
#24 0x00005b9d8f883c66 clang::clangd::BackgroundIndex::index(clang::tooling::CompileCommand) /tmp/llvm-project-main-20260608-latest/clang-tools-extra/clangd/index/Background.cpp:322:42
#25 0x00005b9d8f884997 std::__cxx11::basic_string, std::allocator>::~basic_string() /usr/include/c++/13/bits/basic_string.h:804:19
#26 0x00005b9d8f884997 clang::tooling::CompileCommand::~CompileCommand() /tmp/llvm-project-main-20260608-latest/clang/include/clang/Tooling/CompilationDatabase.h:44:8
#27 0x00005b9d8f884997 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
#28 0x00005b9d8f88fbfe std::_Optional_base_impl>::_M_get() /usr/include/c++/13/optional:479:2
#29 0x00005b9d8f88fbfe std::optional::operator->() /usr/include/c++/13/optional:968:45
#30 0x00005b9d8f88fbfe clang::clangd::BackgroundQueue::work(std::function) /tmp/llvm-project-main-20260608-latest/clang-tools-extra/clangd/index/BackgroundQueue.cpp:44:13
#31 0x00005b9d8f87f8cb std::_Function_base::~_Function_base() /usr/include/c++/13/bits/std_function.h:243:11
#32 0x00005b9d8f87f8cb std::function::~function() /usr/include/c++/13/bits/std_function.h:334:11
#33 0x00005b9d8f87f8cb operator() /tmp/llvm-project-main-20260608-latest/clang-tools-extra/clangd/index/Background.cpp:114:37
#34 0x00005b9d8f87f8cb 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
#35 0x00005b9d8f92216e llvm::detail::UniqueFunctionBase::operator=(llvm::detail::UniqueFunctionBase&&) /tmp/llvm-project-main-20260608-latest/llvm/include/llvm/ADT/FunctionExtras.h:326:5
#36 0x00005b9d8f92216e llvm::detail::UniqueFunctionBase::operator=(llvm::detail::UniqueFunctionBase&&) /tmp/llvm-project-main-20260608-latest/llvm/include/llvm/ADT/FunctionExtras.h:318:23
#37 0x00005b9d8f92216e llvm::unique_function::operator=(llvm::unique_function&&) /tmp/llvm-project-main-20260608-latest/llvm/include/llvm/ADT/FunctionExtras.h:349:20
#38 0x00005b9d8f92216e operator() /tmp/llvm-project-main-20260608-latest/clang-tools-extra/clangd/support/Threading.cpp:103:14
#39 0x00005b9d8f92216e operator())::&> /tmp/llvm-project-main-20260608-latest/llvm/include/llvm/Support/thread.h:46:16
#40 0x00005b9d8f92216e __invoke_impl):: > >(void*)::, clang::clangd::AsyncTaskRunner::runAsync(const llvm::Twine&, llvm::unique_function)::&> /usr/include/c++/13/bits/invoke.h:61:36
#41 0x00005b9d8f92216e __invoke):: > >(void*)::, clang::clangd::AsyncTaskRunner::runAsync(const llvm::Twine&, llvm::unique_function)::&> /usr/include/c++/13/bits/invoke.h:96:40
#42 0x00005b9d8f92216e __apply_impl):: > >(void*)::, std::tuple):: >&, 0> /usr/include/c++/13/tuple:2302:27
#43 0x00005b9d8f92216e apply):: > >(void*)::, std::tuple):: >&> /usr/include/c++/13/tuple:2313:31
#44 0x00005b9d8f92216e GenericThreadProxy):: > > /tmp/llvm-project-main-20260608-latest/llvm/include/llvm/Support/thread.h:44:15
#45 0x00005b9d8f92216e void* llvm::thread::ThreadProxy)::'lambda0'()>>(void*) /tmp/llvm-project-main-20260608-latest/llvm/include/llvm/Support/thread.h:62:36
#46 0x0000743be129caa4 start_thread ./nptl/pthread_create.c:447:8
#47 0x0000743be1329c6c clone3 ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:80:0
Exception ignored in: <_io.TextIOWrapper name='' mode='w' encoding='utf-8'>
BrokenPipeError: [Errno 32] Broken pipe
/harness/scripts/run_clangd_didopen_workspace.sh: line 117: 25198 Exit 120 { emit_lsp "$INIT"; emit_lsp "$INITIALIZED"; emit_lsp "$DIDOPEN"; sleep "$DIDOPEN_WAIT_SECS"; if [[ -n "$POST_OPEN" ]]; then
emit_lsp "$POST_OPEN";
fi; emit_lsp "$SHUTDOWN"; emit_lsp "$EXIT"; }
25199 Aborted (core dumped) | ( cd "$WORKDIR"; "$TARGET" "${TARGET_ARGS[@]}" )
```
Contributor guide
Research direction
Reproduce the crash with the fuzzer input, clangd background indexing, and the listed module, target, language, and standard flags. Read clang/lib/AST/Decl.cpp, clang/lib/Sema/SemaModule.cpp, and clang-tools-extra/clangd/index/Background.cpp around the stack-trace locations. Done means the didOpen sequence and background index no longer hit the ImportDecl assertion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, objective-c
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100