llvm / llvm/llvm-project

[clangd] crash in NumericLiteralParser::NumericLiteralParser

Open
#219,439 4 comments 0 reactions 0 assignees View on GitHub
clangd crash needs-reduction
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

I am posting this as someone versed in clang maybe will be able to extract value from this crash report. I myself have no idea why this crash occurred.

I run Nvim 0.12.4 with clangd 22.1.8 on Linux 7.1.8-arch1-3. clangd crashed (exit code 0, signal 6) when I opened (I suppose) the file `terminal.c`. I have attached a tar archive [foot.tgz](https://github.com/user-attachments/files/31551593/foot.tgz) of the entire project at the exact moment of the crash.

The log from `nvim/lsp.log` around the time of the crash
```
"I[12:25:51.078] <-- textDocument/semanticTokens/full/delta(11909)\n"
"/usr/include/c++/16.1.1/optional:1235: constexpr _Tp* std::optional<_Tp>::operator->() [with _Tp = llvm::sys::unicode::LooseMatchingResult]: Assertion 'this->_M_is_engaged()' failed.\n"
"PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.\nStack dump:\n0.\t/home/peter/foot/terminal.c:835:39 : current parser token 'T \\\n '\n1.\t/home/peter/foot/terminal.c:824:1: parsing function body 'term_set_fonts'\n2.\t/home/peter/foot/terminal.c:824:1: in compound statement ('{}')\n"
"I[12:25:56.395] <-- textDocument/didChange\n"
"I[12:25:56.403] <-- $/cancelRequest\nI[12:25:56.403] <-- textDocument/semanticTokens/full/delta(11910)\n"
"I[12:25:57.273] <-- textDocument/didChange\n"
"I[12:25:57.285] <-- $/cancelRequest\n"
"I[12:25:57.285] <-- textDocument/semanticTokens/full/delta(11911)\n"
```

The stacktrace from `nvim/lsp.log`
```
#0 0x00007f2aaed98297 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /usr/src/debug/llvm/llvm-project-22.1.8.src/llvm/lib/Support/Unix/Signals.inc:842:22\n
#1 0x00007f2aaed95027 llvm::sys::RunSignalHandlers() /usr/src/debug/llvm/llvm-project-22.1.8.src/llvm/lib/Support/Signals.cpp:108:20\n
#2 0x00007f2aaed95027 SignalHandler /usr/src/debug/llvm/llvm-project-22.1.8.src/llvm/lib/Support/Unix/Signals.inc:412:31\n
#3 0x00007f2aadc3e6f0 (/usr/lib/libc.so.6+0x3e6f0)\n
#4 0x00007f2aadc9a17c __pthread_kill_implementation /usr/src/debug/glibc/glibc/nptl/pthread_kill.c:44:76\n
#5 0x00007f2aadc3e5d0 raise /usr/src/debug/glibc/glibc/signal/../sysdeps/posix/raise.c:27:6\n
#6 0x00007f2aadc25685 abort /usr/src/debug/glibc/glibc/stdlib/abort.c:85:3\n
#7 0x00007f2aae09d5bd (/usr/lib/libstdc++.so.6+0x9d5bd)\n
#8 0x00007f2ab8f74b7f (/usr/lib/libclang-cpp.so.22.1+0x574b7f)\n
#9 0x00007f2ab9214e10 clang::NumericLiteralParser::NumericLiteralParser(llvm::StringRef, clang::SourceLocation, clang::SourceManager const&, clang::LangOptions const&, clang::TargetInfo const&, clang::DiagnosticsEngine&) /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Lex/LiteralSupport.cpp:1176:24\n
#10 0x00007f2aba471d1a clang::Sema::ActOnNumericConstant(clang::Token const&, clang::Scope*) /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Sema/SemaExpr.cpp:3742:3\n
#11 0x00007f2ab93401bd clang::Parser::ParseCastExpression(clang::CastParseKind, bool, bool&, clang::TypoCorrectionTypeBehavior, bool, bool*) /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Parse/ParseExpr.cpp:801:39\n
#12 0x00007f2ab93424cb clang::Parser::ParseCastExpression(clang::CastParseKind, bool, clang::TypoCorrectionTypeBehavior, bool, bool*) /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Parse/ParseExpr.cpp:570:3\n
#13 0x00007f2ab93437fa clang::Parser::ParseRHSOfBinaryExpression(clang::ActionResult, clang::prec::Level) /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Parse/ParseExpr.cpp:461:32\n
#14 0x00007f2ab934b615 clang::Parser::ParseExpression(clang::TypoCorrectionTypeBehavior) /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Parse/ParseExpr.cpp:49:36\n
#15 0x00007f2ab934b615 clang::Parser::ParseParenExpression(clang::ParenParseOption&, bool, clang::ParenExprKind, clang::TypoCorrectionTypeBehavior, clang::OpaquePtr&, clang::SourceLocation&) /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Parse/ParseExpr.cpp:2925:29\n
#16 0x00007f2ab9340507 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, bool&, clang::TypoCorrectionTypeBehavior, bool, bool*) /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Parse/ParseExpr.cpp:763:31\n
#17 0x00007f2ab93424cb clang::Parser::ParseCastExpression(clang::CastParseKind, bool, clang::TypoCorrectionTypeBehavior, bool, bool*) /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Parse/ParseExpr.cpp:570:3\n
#18 0x00007f2ab93426e8 clang::Parser::ParseAssignmentExpression(clang::TypoCorrectionTypeBehavior) /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Parse/ParseExpr.cpp:92:36\n
#19 0x00007f2ab9342841 clang::Token::is(clang::tok::TokenKind) const /usr/src/debug/clang/llvm-project-22.1.8.src/clang/include/clang/Lex/Token.h:102:44\n
#20 0x00007f2ab9342841 clang::Parser::ParseExpressionList(llvm::SmallVectorImpl&, llvm::function_ref, bool) /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Parse/ParseExpr.cpp:3182:15\n
#21 0x00007f2ab934793f clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult) /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Parse/ParseExpr.cpp:1852:11\n
#22 0x00007f2ab933f9b2 clang::Parser::ParseCastExpression(clang::CastParseKind, bool, bool&, clang::TypoCorrectionTypeBehavior, bool, bool*) /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Parse/ParseExpr.cpp:1622:37\n
#23 0x00007f2ab93424cb clang::Parser::ParseCastExpression(clang::CastParseKind, bool, clang::TypoCorrectionTypeBehavior, bool, bool*) /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Parse/ParseExpr.cpp:570:3\n
#24 0x00007f2ab934db89 clang::Parser::ParseAssignmentExpression(clang::TypoCorrectionTypeBehavior) /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Parse/ParseExpr.cpp:92:36\n
#25 0x00007f2ab934db89 clang::Parser::ParseExpression(clang::TypoCorrectionTypeBehavior) /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Parse/ParseExpr.cpp:48:43\n
#26 0x00007f2ab93f4fe2 clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Parse/ParseStmt.cpp:529:3\n
#27 0x00007f2ab93eadb4 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::LabelDecl*) /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Parse/ParseStmt.cpp:253:40\n
#28 0x00007f2ab93eb9e6 clang::Parser::MaybeDestroyTemplateIds() /usr/src/debug/clang/llvm-project-22.1.8.src/clang/include/clang/Parse/Parser.h:7820:5\n
#29 0x00007f2ab93eb9e6 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::LabelDecl*) /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Parse/ParseStmt.cpp:81:26\n
#30 0x00007f2ab93ecfd2 clang::ActionResult::isInvalid() const /usr/src/debug/clang/llvm-project-22.1.8.src/clang/include/clang/Sema/Ownership.h:200:44\n
#31 0x00007f2ab93ecfd2 clang::Parser::ParseCompoundStatementBody(bool) /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Parse/ParseStmt.cpp:1209:30\n
#32 0x00007f2ab93ed8c4 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Parse/ParseStmt.cpp:2455:47\n
#33 0x00007f2ab94254d2 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Parse/Parser.cpp:1441:36\n
#34 0x00007f2ab9309ae2 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Parse/ParseDecl.cpp:2265:40\n
#35 0x00007f2ab941f6e8 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Parse/Parser.cpp:1180:73\n
#36 0x00007f2ab941ff0d clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Parse/Parser.cpp:1202:42\n
#37 0x00007f2ab9429502 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Parse/Parser.cpp:1030:50\n
#38 0x00007f2ab942a97c clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Parse/Parser.cpp:743:36\n
#39 0x00007f2ab92d0ceb clang::ParseAST(clang::Sema&, bool, bool) /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Parse/ParseAST.cpp:169:69\n
#40 0x00007f2abbaf8aeb clang::FrontendAction::Execute() /usr/src/debug/clang/llvm-project-22.1.8.src/clang/lib/Frontend/FrontendAction.cpp:1317:38\n
#41 0x00005649cede3173 llvm::Error::getPtr() const /usr/include/llvm/Support/Error.h:281:12\n
#42 0x00005649cede3173 llvm::Error::operator bool() /usr/include/llvm/Support/Error.h:241:22\n
#43 0x00005649cede3173 clang::clangd::ParsedAST::build(llvm::StringRef, clang::clangd::ParseInputs const&, std::unique_ptr>, llvm::ArrayRef, std::shared_ptr) /usr/src/debug/clang/llvm-project-22.1.8.src/clang-tools-extra/clangd/ParsedAST.cpp:714:42\n
#44 0x00005649cee78733 std::_Optional_payload_base::_M_move_assign(std::_Optional_payload_base&&) /usr/include/c++/16.1.1/optional:208:2\n
#45 0x00005649cee78733 std::_Optional_payload::operator=(std::_Optional_payload&&) /usr/include/c++/16.1.1/optional:463:22\n
#46 0x00005649cee78733 std::_Optional_payload::operator=(std::_Optional_payload&&) /usr/include/c++/16.1.1/optional:479:26\n
#47 0x00005649cee78733 std::_Optional_base::operator=(std::_Optional_base&&) /usr/include/c++/16.1.1/optional:556:23\n
#48 0x00005649cee78733 std::optional::operator=(std::optional&&) /usr/include/c++/16.1.1/optional:810:11\n
#49 0x00005649cee78733 operator() /usr/src/debug/clang/llvm-project-22.1.8.src/clang-tools-extra/clangd/TUScheduler.cpp:1000:61\n
#50 0x00005649cee7b47d runTask /usr/src/debug/clang/llvm-project-22.1.8.src/clang-tools-extra/clangd/TUScheduler.cpp:1328:1\n
#51 0x00005649cee7d7fe std::__shared_ptr::__shared_ptr(std::__shared_ptr&&) /usr/include/c++/16.1.1/bits/shared_ptr_base.h:1618:9\n
#52 0x00005649cee7d7fe std::shared_ptr::shared_ptr(std::shared_ptr&&) /usr/include/c++/16.1.1/bits/shared_ptr.h:359:41\n
#53 0x00005649cee7d7fe clang::clangd::Context::Context(clang::clangd::Context&&) /usr/src/debug/clang/llvm-project-22.1.8.src/clang-tools-extra/clangd/support/Context.h:92:3\n
#54 0x00005649cee7d7fe clang::clangd::WithContext::~WithContext() /usr/src/debug/clang/llvm-project-22.1.8.src/clang-tools-extra/clangd/support/Context.h:188:40\n
#55 0x00005649cee7d7fe run /usr/src/debug/clang/llvm-project-22.1.8.src/clang-tools-extra/clangd/TUScheduler.cpp:1462:5\n
#56 0x00005649cf07f50e memcpy /usr/include/bits/string_fortified.h:29:33\n
#57 0x00005649cf07f50e llvm::detail::PunnedPointer::TrivialCallback*, llvm::detail::UniqueFunctionBase::NonTrivialCallbacks*>>::asInt() const /usr/include/llvm/ADT/PointerIntPair.h:41:16\n
#58 0x00005649cf07f50e llvm::detail::PunnedPointer::TrivialCallback*, llvm::detail::UniqueFunctionBase::NonTrivialCallbacks*>>::operator long() const /usr/include/llvm/ADT/PointerIntPair.h:45:53\n
#59 0x00005649cf07f50e llvm::PointerIntPair::TrivialCallback*, llvm::detail::UniqueFunctionBase::NonTrivialCallbacks*>, 1u, bool, llvm::PointerLikeTypeTraits::TrivialCallback*, llvm::detail::UniqueFunctionBase::NonTrivialCallbacks*>>, llvm::PointerIntPairInfo::TrivialCallback*, llvm::detail::UniqueFunctionBase::NonTrivialCallbacks*>, 1u, llvm::PointerLikeTypeTraits::TrivialCallback*, llvm::detail::UniqueFunctionBase::NonTrivialCallbacks*>>>>::getPointer() const /usr/include/llvm/ADT/PointerIntPair.h:94:57\n
#60 0x00005649cf07f50e llvm::detail::UniqueFunctionBase::~UniqueFunctionBase() /usr/include/llvm/ADT/FunctionExtras.h:274:42\n
#61 0x00005649cf07f50e llvm::detail::UniqueFunctionBase::operator=(llvm::detail::UniqueFunctionBase&&) /usr/include/llvm/ADT/FunctionExtras.h:328:30\n
#62 0x00005649cf07f50e llvm::unique_function::operator=(llvm::unique_function&&) /usr/include/llvm/ADT/FunctionExtras.h:352:20\n
#63 0x00005649cf07f50e operator() /usr/src/debug/clang/llvm-project-22.1.8.src/clang-tools-extra/clangd/support/Threading.cpp:103:14\n
#64 0x00005649cf07f50e operator())::&> /usr/include/llvm/Support/thread.h:46:16\n
#65 0x00005649cf07f50e __invoke_impl):: > >(void*)::, clang::clangd::AsyncTaskRunner::runAsync(const llvm::Twine&, llvm::unique_function)::&> /usr/include/c++/16.1.1/bits/invoke.h:63:36\n
#66 0x00005649cf07f50e __invoke):: > >(void*)::, clang::clangd::AsyncTaskRunner::runAsync(const llvm::Twine&, llvm::unique_function)::&> /usr/include/c++/16.1.1/bits/invoke.h:98:40\n
#67 0x00005649cf07f50e __apply_impl):: > >(void*)::, std::tuple):: >&, 0> /usr/include/c++/16.1.1/tuple:2976:27\n
#68 0x00005649cf07f50e apply):: > >(void*)::, std::tuple):: >&> /usr/include/c++/16.1.1/tuple:2991:31\n
#69 0x00005649cf07f50e GenericThreadProxy):: > > /usr/include/llvm/Support/thread.h:44:15\n
#70 0x00005649cf07f50e ThreadProxy):: > > /usr/include/llvm/Support/thread.h:58:36\n
#71 0x00007f2aadc980a2 start_thread /usr/src/debug/glibc/glibc/nptl/pthread_create.c:454:8\n
#72 0x00007f2aadd2080c __GI___clone3 /usr/src/debug/glibc/glibc/misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:80:0\nSignalled during AST worker action: SemanticHighlights\n Filename: ../terminal.c\n Directory: /home/peter/foot/build\n Command Line: /usr/bin/cc -Ilibpgolib.a.p -I. -I.. -Isubprojects/fcft -I../subprojects/fcft -Isubprojects/tllist -I../subprojects/tllist -I/usr/include/pixman-1 -fdiagnostics-color=always -DNDEBUG -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c11 -O3 -DMEMFD_CREATE -DEXECVPE -DSIGABBREV_NP -D_GNU_SOURCE=200809L -DFOOT_DEFAULT_TERM="foot" -DUTMP_ADD="add" -DUTMP_DEL="del" -DUTMP_DEFAULT_HELPER_PATH="/usr/lib/utempter/utempter" -fno-asynchronous-unwind-tables -DFOOT_IME_ENABLED=1 -pedantic -fstrict-aliasing -Wstrict-aliasing -fmacro-prefix-map=../= -DFOOT_GRAPHEME_CLUSTERING=1 -DHAVE_PIXMAN_RGBA_16 -DHAVE_XDG_TOPLEVEL_TAG=1 -DHAVE_EXT_BACKGROUND_EFFECT=1 -fPIC -DUTF8PROC_EXPORTS -MD -MQ libpgolib.a.p/terminal.c.o -MF libpgolib.a.p/terminal.c.o.d -o libpgolib.a.p/terminal.c.o -c -Wno-c2y-extensions -resource-dir=/usr/lib/clang/22 -- /home/peter/foot/terminal.c\n Version: 1193\n'
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the crash using the attached foot.tgz project and the clangd log, starting at terminal.c:835 and the reported token context. Read clang/lib/Lex/LiteralSupport.cpp:1176, then follow the call into clang-tools-extra/clangd/ParsedAST.cpp:714 to determine why the assertion is reached. Done means the archive no longer causes clangd to abort and the failure has a reliable regression check.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.