Clangd breaks on opening file
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Clangd crashes when I open a [specific file](https://gist.github.com/Ezuharad/1a413d06d87ecc2157bcce876ef4ec82) in my project.
My `compile_commands.json`:
```json
[
{
"directory": "/home/ezuharad/Code/domino/build",
"command": "clang++ -std=c++23 -o CMakeFiles/domino.dir/src/test_vec.cpp.o -c /home/ezuharad/Code/domino/src/test_vec.cpp",
"file": "/home/ezuharad/Code/domino/src/test_vec.cpp",
"output": "CMakeFiles/domino.dir/src/test_vec.cpp.o"
}
]
```
The resulting lsp logs from nvim:
```
[START][2026-06-08 21:02:45] LSP logging initiated
[ERROR][2026-06-08 21:02:45] /usr/share/nvim/runtime/lua/vim/lsp/log.lua:151 "rpc" "clangd" "stderr" "I[21:02:45.190] clangd version 22.1.6 (https://github.com/llvm/llvm-project fc4aad7b5db3fff421df9a9637605b9ca5667881)\nI[21:02:45.190] Features: linux+grpc\nI[21:02:45.190] PID: 19958\nI[21:02:45.190] Working directory: /home/ezuharad/Code/domino\nI[21:02:45.190] argv[0]: clangd\nI[21:02:45.190] argv[1]: --background-index\nI[21:02:45.190] argv[2]: --clang-tidy\nI[21:02:45.190] argv[3]: --header-insertion=iwyu\nI[21:02:45.190] argv[4]: --completion-style=detailed\nI[21:02:45.190] argv[5]: --function-arg-placeholders\nI[21:02:45.190] argv[6]: --fallback-style=llvm\nE[21:02:45.190] Value specified by --function-arg-placeholders is invalid. Provide a boolean value or leave unspecified to use ArgumentListsPolicy from config instead.\nI[21:02:45.190] Starting LSP over stdin/stdout\nI[21:02:45.190] <-- initialize(1)\nE[21:02:45.190] offsetEncoding capability is a deprecated clangd extension that'll go away with clangd 23. Migrate to standard positionEncodings capability introduced by LSP 3.17\nI[21:02:45.191] --> reply:initialize(1) 0 ms\n"
[ERROR][2026-06-08 21:02:45] /usr/share/nvim/runtime/lua/vim/lsp/log.lua:151 "rpc" "clangd" "stderr" "I[21:02:45.433] <-- initialized\nI[21:02:45.434] <-- textDocument/didOpen\n"
[ERROR][2026-06-08 21:02:45] /usr/share/nvim/runtime/lua/vim/lsp/log.lua:151 "rpc" "clangd" "stderr" "I[21:02:45.434] Loaded compilation database from /home/ezuharad/Code/domino/compile_commands.json\nI[21:02:45.434] --> window/workDoneProgress/create(0)\nI[21:02:45.434] ASTWorker building file /home/ezuharad/Code/domino/src/vec.hpp version 0 with command inferred from /home/ezuharad/Code/domino/src/test_vec.cpp\n[/home/ezuharad/Code/domino/build]\n/usr/bin/clang++ --driver-mode=g++ -c -std=c++23 -resource-dir=/home/ezuharad/.local/share/nvim/mason/packages/clangd/clangd_22.1.6/lib/clang/22 -- /home/ezuharad/Code/domino/src/vec.hpp\nI[21:02:45.434] Enqueueing 1 commands for indexing\n"
[ERROR][2026-06-08 21:02:45] /usr/share/nvim/runtime/lua/vim/lsp/log.lua:151 "rpc" "clangd" "stderr" "I[21:02:45.436] --> textDocument/clangd.fileStatus\n"
[ERROR][2026-06-08 21:02:45] /usr/share/nvim/runtime/lua/vim/lsp/log.lua:151 "rpc" "clangd" "stderr" "I[21:02:45.452] <-- textDocument/documentSymbol(2)\n"
[ERROR][2026-06-08 21:02:45] /usr/share/nvim/runtime/lua/vim/lsp/log.lua:151 "rpc" "clangd" "stderr" "I[21:02:45.547] <-- textDocument/inlayHint(3)\nI[21:02:45.547] <-- textDocument/semanticTokens/full(4)\n"
[ERROR][2026-06-08 21:02:45] /usr/share/nvim/runtime/lua/vim/lsp/log.lua:151 "rpc" "clangd" "stderr" "I[21:02:45.547] <-- reply(0)\nI[21:02:45.547] --> $/progress\nI[21:02:45.547] --> $/progress\n"
[ERROR][2026-06-08 21:02:45] /usr/share/nvim/runtime/lua/vim/lsp/log.lua:151 "rpc" "clangd" "stderr" "I[21:02:45.578] <-- textDocument/foldingRange(5)\n"
[ERROR][2026-06-08 21:02:45] /usr/share/nvim/runtime/lua/vim/lsp/log.lua:151 "rpc" "clangd" "stderr" "I[21:02:45.583] --> reply:textDocument/foldingRange(5) 5 ms\n"
[ERROR][2026-06-08 21:02:46] /usr/share/nvim/runtime/lua/vim/lsp/log.lua:151 "rpc" "clangd" "stderr" "I[21:02:46.183] Built preamble of size 13373008 for file /home/ezuharad/Code/domino/src/vec.hpp version 0 in 0.75 seconds\n"
[ERROR][2026-06-08 21:02:46] /usr/share/nvim/runtime/lua/vim/lsp/log.lua:151 "rpc" "clangd" "stderr" "I[21:02:46.183] --> workspace/semanticTokens/refresh(1)\n"
[ERROR][2026-06-08 21:02:46] /usr/share/nvim/runtime/lua/vim/lsp/log.lua:151 "rpc" "clangd" "stderr" "I[21:02:46.183] Indexing c++23 standard library in the context of /home/ezuharad/Code/domino/src/vec.hpp\n"
[ERROR][2026-06-08 21:02:46] /usr/share/nvim/runtime/lua/vim/lsp/log.lua:151 "rpc" "clangd" "stderr" "I[21:02:46.183] <-- $/cancelRequest\nI[21:02:46.184] <-- reply(1)\n"
[ERROR][2026-06-08 21:02:46] /usr/share/nvim/runtime/lua/vim/lsp/log.lua:151 "rpc" "clangd" "stderr" "I[21:02:46.260] --> textDocument/publishDiagnostics\n"
[ERROR][2026-06-08 21:02:46] /usr/share/nvim/runtime/lua/vim/lsp/log.lua:151 "rpc" "clangd" "stderr" "I[21:02:46.264] --> reply:textDocument/documentSymbol(2) 812 ms\n"
[ERROR][2026-06-08 21:02:46] /usr/share/nvim/runtime/lua/vim/lsp/log.lua:151 "rpc" "clangd" "stderr" "PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.\nI[21:02:46.383] <-- textDocument/semanticTokens/full(6)\n"
[ERROR][2026-06-08 21:02:47] /usr/share/nvim/runtime/lua/vim/lsp/log.lua:151 "rpc" "clangd" "stderr" " #0 0x0000000000510e67 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /__w/clangd/clangd/llvm-project/llvm/lib/Support/Unix/Signals.inc:842:13\n #1 0x000000000050e8a5 llvm::sys::RunSignalHandlers() /__w/clangd/clangd/llvm-project/llvm/lib/Support/Signals.cpp:109:18\n #2 0x0000000000511dca SignalHandler(int, siginfo_t*, void*) /__w/clangd/clangd/llvm-project/llvm/lib/Support/Unix/Signals.inc:429:38\n #3 0x00007f55bb43e8f0 (/usr/lib/libc.so.6+0x3e8f0)\n #4 0x000000000166c019 getStmtClass /__w/clangd/clangd/llvm-project/clang/include/clang/AST/Stmt.h:1485:44\n #5 0x000000000166c019 classof /__w/clangd/clangd/llvm-project/clang/include/clang/AST/ExprCXX.h:4417:15\n #6 0x000000000166c019 doit /__w/clangd/clangd/llvm-project/llvm/include/llvm/Support/Casting.h:64:53\n #7 0x000000000166c019 doit /__w/clangd/clangd/llvm-project/llvm/include/llvm/Support/Casting.h:110:12\n #8 0x000000000166c019 doit /__w/clangd/clangd/llvm-project/llvm/include/llvm/Support/Casting.h:137:12\n #9 0x000000000166c019 doit /__w/clangd/clangd/llvm-project/llvm/include/llvm/Support/Casting.h:127:12\n#10 0x000000000166c019 isPossible /__w/clangd/clangd/llvm-project/llvm/include/llvm/Support/Casting.h:255:12\n#11 0x000000000166c019 isPossible /__w/clangd/clangd/llvm-project/llvm/include/llvm/Support/Casting.h:509:12\n#12 0x000000000166c019 isa /__w/clangd/clangd/llvm-project/llvm/include/llvm/Support/Casting.h:548:11\n#13 0x000000000166c019 clang::clangd::(anonymous namespace)::InlayHintVisitor::processCall(clang::clangd::(anonymous namespace)::Callee, clang::SourceLocation, llvm::ArrayRef) /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/InlayHints.cpp:801:11\n#14 0x0000000001669c51 ~_Vector_base /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_vector.h:332:24\n#15 0x0000000001669c51 ~vector /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_vector.h:680:7\n#16 0x0000000001669c51 VisitCallExpr /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/InlayHints.cpp:498:3\n#17 0x0000000001669c51 clang::RecursiveASTVisitor::WalkUpFromCallExpr(clang::CallExpr*) /__w/clangd/clangd/clangd_22.1.6/tools/clang/include/clang/AST/StmtNodes.inc:614:1\n#18 0x000000000165d829 TraverseCallExpr /__w/clangd/clangd/llvm-project/clang/include/clang/AST/RecursiveASTVisitor.h:0:1\n#19 0x000000000165d829 clang::RecursiveASTVisitor::dataTraverseNode(clang::Stmt*, llvm::SmallVectorImpl, llvm::PointerIntPairInfo>>>*) /__w/clangd/clangd/clangd_22.1.6/tools/clang/include/clang/AST/StmtNodes.inc:614:1\n#20 0x0000000001658abf clang::RecursiveASTVisitor::TraverseStmt(clang::Stmt*, llvm::SmallVectorImpl, llvm::PointerIntPairInfo>>>*) /__w/clangd/clangd/llvm-project/clang/include/clang/AST/RecursiveASTVisitor.h:695:7\n#21 0x000000000166f241 clang::RecursiveASTVisitor::TraverseFunctionHelper(clang::FunctionDecl*) /__w/clangd/clangd/llvm-project/clang/include/clang/AST/RecursiveASTVisitor.h:2386:5\n#22 0x0000000001653798 TraverseCXXMethodDecl /__w/clangd/clangd/llvm-project/clang/include/clang/AST/RecursiveASTVisitor.h:2411:1\n#23 0x0000000001653798 clang::RecursiveASTVisitor::TraverseDecl(clang::Decl*) /__w/clangd/clangd/clangd_22.1.6/tools/clang/include/clang/AST/DeclNodes.inc:260:1\n#24 0x0000000001654b9b TraverseDeclContextHelper /__w/clangd/clangd/llvm-project/clang/include/clang/AST/RecursiveASTVisitor.h:1637:7\n#25 0x0000000001654b9b TraverseCXXRecordDecl /__w/clangd/clangd/llvm-project/clang/include/clang/AST/RecursiveASTVisitor.h:2175:1\n#26 0x0000000001654b9b clang::RecursiveASTVisitor::TraverseDecl(clang::Decl*) /__w/clangd/clangd/clangd_22.1.6/tools/clang/include/clang/AST/DeclNodes.inc:432:1\n#27 0x0000000001654ffb TraverseClassTemplateDecl /__w/clangd/clangd/llvm-project/clang/include/clang/AST/RecursiveASTVisitor.h:2062:1\n#28 0x0000000001654ffb clang::RecursiveASTVisitor::TraverseDecl(clang::Decl*) /__w/clangd/clangd/clangd_22.1.6/tools/clang/include/clang/AST/DeclNodes.inc:542:1\n#29 0x00000000016576b0 TraverseDeclContextHelper /__w/clangd/clangd/llvm-project/clang/include/clang/AST/RecursiveASTVisitor.h:1637:7\n#30 0x00000000016576b0 TraverseNamespaceDecl /__w/clangd/clangd/llvm-project/clang/include/clang/AST/RecursiveASTVisitor.h:1781:1\n#31 0x00000000016576b0 clang::RecursiveASTVisitor::TraverseDecl(clang::Decl*) /__w/clangd/clangd/clangd_22.1.6/tools/clang/include/clang/AST/DeclNodes.inc:584:1\n#32 0x00000000016521ac TraverseTranslationUnitDecl /__w/clangd/clangd/llvm-project/clang/include/clang/AST/RecursiveASTVisitor.h:1745:1\n#33 0x00000000016521ac clang::RecursiveASTVisitor::TraverseDecl(clang::Decl*) /__w/clangd/clangd/clangd_22.1.6/tools/clang/include/clang/AST/DeclNodes.inc:24:1\n#34 0x0000000001651cfe __normal_iterator /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_iterator.h:804:20\n#35 0x0000000001651cfe begin /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_vector.h:809:16\n#36 0x0000000001651cfe begin > > /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/range_access.h:49:21\n#37 0x0000000001651cfe begin_impl > &> /__w/clangd/clangd/llvm-project/llvm/include/llvm/ADT/ADL.h:29:10\n#38 0x0000000001651cfe adl_begin > &> /__w/clangd/clangd/llvm-project/llvm/include/llvm/ADT/ADL.h:80:10\n#39 0x0000000001651cfe sort > &> /__w/clangd/clangd/llvm-project/llvm/include/llvm/ADT/STLExtras.h:1648:14\n#40 0x0000000001651cfe clang::clangd::inlayHints(clang::clangd::ParsedAST&, std::optional, clang::clangd::InlayHintOptions) /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/InlayHints.cpp:1212:3\n#41 0x0000000001584ddd Expected > > /__w/clangd/clangd/llvm-project/llvm/include/llvm/Support/Error.h:528:9\n#42 0x0000000001584ddd operator() /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/ClangdServer.cpp:926:8\n#43 0x0000000001584ddd void llvm::detail::UniqueFunctionBase>::CallImpl, llvm::unique_function>>)>)::$_16>(void*, llvm::Expected&) /__w/clangd/clangd/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:212:12\n#44 0x00000000017255c4 ~Expected /__w/clangd/clangd/llvm-project/llvm/include/llvm/Support/Error.h:567:10\n#45 0x00000000017255c4 operator() /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/TUScheduler.cpp:1012:5\n#46 0x00000000017255c4 void llvm::detail::UniqueFunctionBase::CallImpl)>, clang::clangd::TUScheduler::ASTActionInvalidation)::$_3>(void*) /__w/clangd/clangd/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:212:12\n#47 0x000000000171d583 operator() /__w/clangd/clangd/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:0:12\n#48 0x000000000171d583 clang::clangd::(anonymous namespace)::ASTWorker::runTask(llvm::StringRef, llvm::function_ref) /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/TUScheduler.cpp:1327:3\n#49 0x000000000171c55d run /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/TUScheduler.cpp:1462:5\n#50 0x000000000171c55d operator() /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/TUScheduler.cpp:826:42\n#51 0x000000000171c55d void llvm::detail::UniqueFunctionBase::CallImpl(void*) /__w/clangd/clangd/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:212:12\n#52 0x000000000189c3b6 operator= /__w/clangd/clangd/llvm-project/llvm/include/llvm/ADT/PointerIntPair.h:48:5\n#53 0x000000000189c3b6 PunnedPointer /__w/clangd/clangd/llvm-project/llvm/include/llvm/ADT/PointerIntPair.h:37:60\n#54 0x000000000189c3b6 PointerIntPair /__w/clangd/clangd/llvm-project/llvm/include/llvm/ADT/PointerIntPair.h:86:13\n#55 0x000000000189c3b6 UniqueFunctionBase /__w/clangd/clangd/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:333:3\n#56 0x000000000189c3b6 unique_function /__w/clangd/clangd/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:349:3\n#57 0x000000000189c3b6 operator() /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:103:14\n#58 0x000000000189c3b6 operator()<(lambda at /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:98:15) &> /__w/clangd/clangd/llvm-project/llvm/include/llvm/Support/thread.h:46:11\n#59 0x000000000189c3b6 __invoke_impl /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/invoke.h:60:14\n#60 0x000000000189c3b6 __invoke<(lambda at /__w/clangd/clangd/llvm-project/llvm/include/llvm/Support/thread.h:45:9), (lambda at /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:98:15) &> /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/invoke.h:95:14\n#61 0x000000000189c3b6 __apply_impl<(lambda at /__w/clangd/clangd/llvm-project/llvm/include/llvm/Support/thread.h:45:9), std::tuple<(lambda at /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:98:15)> &, 0> /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/tuple:1684:14\n#62 0x000000000189c3b6 apply<(lambda at /__w/clangd/clangd/llvm-project/llvm/include/llvm/Support/thread.h:45:9), std::tuple<(lambda at /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:98:15)> &> /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/tuple:1694:14\n#63 0x000000000189c3b6 GenericThreadProxy > /__w/clangd/clangd/llvm-project/llvm/include/llvm/Support/thread.h:44:5\n#64 0x000000000189c3b6 void* llvm::thread::ThreadProxy)::$_1>>(void*) /__w/clangd/clangd/llvm-project/llvm/include/llvm/Support/thread.h:58:5\n#65 0x00007f55bb4981b9 start_thread /usr/src/debug/glibc/glibc/nptl/pthread_create.c:454:8\n#66 0x00007f55bb51d21c __GI___clone3 /usr/src/debug/glibc/glibc/misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:80:0\nSignalled during AST worker action: InlayHints\n Filename: /home/ezuharad/Code/domino/src/vec.hpp\n Directory: /home/ezuharad/Code/domino/build\n Command Line: /usr/bin/clang++ --driver-mode=g++ -c -std=c++23 -resource-dir=/home/ezuharad/.local/share/nvim/mason/packages/clangd/clangd_22.1.6/lib/clang/22 -- /home/ezuharad/Code/domino/src/vec.hpp\n Version: 0\n"
```
I apologize if this bug report is not in the correct format or is nonspecific. The [LLVM bug reporting guidelines](https://llvm.org/docs/HowToSubmitABug.html) seem tailored specifically to compiler bugs (specifically clang), and not LSP bugs. Additionally, I have not written C++ code in quite some time, so I may be forgetting to include something important. I am happy to provide any further information as necessary.
Contributor guide
Research direction
Reproduce the crash by opening the linked file with the shown compile_commands.json and clangd inlay hints enabled. Start in clang-tools-extra/clangd/InlayHints.cpp at processCall and inlayHints, using the stack trace to follow the failing AST cast; done means opening the file and requesting inlay hints no longer crashes clangd.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, neovim
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100