clangd / clangd

clangd language server
https://clangd.llvm.org
Apache License 2.0
1.43k stars 61 forks source link

Crash of clangd while indexing #1841

Open domwst opened 7 months ago

domwst commented 7 months ago

I'm working on a relatively large project, and after I start clangd, it crashes after several minutes due to a SIGSEGV with the attached stack trace.

Unfortunately, the project is quite big so it will take up a lot of time to narrow down to the exact file, where the error occurs. The RAM shouldn't be a concern in this case, as I have more than 10GB of a free RAM all the time that clangd works.

I run clangd as follows:

clangd --background-index -j=8 --header-insertion=never

Logs

 #0 0x00000000004f367b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /__w/clangd/clangd/llvm-project/llvm/lib/Support/Unix/Signals.inc:602:13
 #1 0x00000000004f167c llvm::sys::RunSignalHandlers() /__w/clangd/clangd/llvm-project/llvm/lib/Support/Signals.cpp:105:18
 #2 0x00000000004f3fe6 SignalHandler(int) /__w/clangd/clangd/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
 #3 0x00007f229e4ff420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x0000000000a4f259 getLocation /__w/clangd/clangd/llvm-project/clang/include/clang/AST/DeclBase.h:432:47
 #5 0x0000000000a4f259 clang::Sema::LookupSpecialMember(clang::CXXRecordDecl*, clang::Sema::CXXSpecialMember, bool, bool, bool, bool, bool) /__w/clangd/clangd/llvm-project/clang/lib/Sema/SemaLookup.cpp:3335:34
 #6 0x0000000000a504e4 clang::Sema::LookupDefaultConstructor(clang::CXXRecordDecl*) /__w/clangd/clangd/llvm-project/clang/lib/Sema/SemaLookup.cpp:3539:5
 #7 0x000000000108b420 TryValueInitialization(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, clang::InitializationSequence&, clang::InitListExpr*) /__w/clangd/clangd/llvm-project/clang/lib/Sema/SemaInit.cpp:5329:12
 #8 0x000000000108813f clang::InitializationSequence::InitializeFrom(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>, bool, bool) /__w/clangd/clangd/llvm-project/clang/lib/Sema/SemaInit.cpp:6221:5
 #9 0x00000000010a6be2 operator() /__w/clangd/clangd/llvm-project/clang/lib/Sema/SemaInit.cpp:0:0
#10 0x00000000010a6be2 TryOrBuildParenListInitialization(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::ArrayRef<clang::Expr*>, clang::InitializationSequence&, bool, clang::ActionResult<clang::Expr*, true>*)::$_12::operator()(clang::InitializedEntity const&, clang::InitializationKind const&, clang::Expr*, clang::Expr**) const /__w/clangd/clangd/llvm-project/clang/lib/Sema/SemaInit.cpp:5426:33
#11 0x000000000108bde5 TryOrBuildParenListInitialization(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::ArrayRef<clang::Expr*>, clang::InitializationSequence&, bool, clang::ActionResult<clang::Expr*, true>*) /__w/clangd/clangd/llvm-project/clang/lib/Sema/SemaInit.cpp:5619:16
#12 0x0000000001089749 clang::InitializationSequence::InitializeFrom(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>, bool, bool) /__w/clangd/clangd/llvm-project/clang/lib/Sema/SemaInit.cpp:0:7
#13 0x0000000000fece05 clang::Sema::BuildCXXTypeConstructExpr(clang::TypeSourceInfo*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, bool) /__w/clangd/clangd/llvm-project/clang/lib/Sema/SemaExprCXX.cpp:1588:31
#14 0x0000000000fec533 clang::Sema::ActOnCXXTypeConstructExpr(clang::OpaquePtr<clang::QualType>, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, bool) /__w/clangd/clangd/llvm-project/clang/lib/Sema/SemaExprCXX.cpp:1449:17
#15 0x0000000002141012 clang::Parser::ParseCXXTypeConstructExpression(clang::DeclSpec const&) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseExprCXX.cpp:1981:20
#16 0x0000000002128159 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseExpr.cpp:1594:9
#17 0x000000000212c2d0 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseExpr.cpp:0:0
#18 0x0000000002124d21 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, clang::Parser::TypeCastState, bool, bool*) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseExpr.cpp:683:20
#19 0x00000000021234fc clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseExpr.cpp:178:10
#20 0x000000000213430a clang::Parser::ParseExpressionList(llvm::SmallVectorImpl<clang::Expr*>&, llvm::function_ref<void ()>, bool, bool) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseExpr.cpp:0:0
#21 0x0000000002125b0d clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr*, true>) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseExpr.cpp:2085:15
#22 0x000000000212743d clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseExpr.cpp:1852:9
#23 0x0000000002124d21 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, clang::Parser::TypeCastState, bool, bool*) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseExpr.cpp:683:20
#24 0x00000000021234fc clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseExpr.cpp:178:10
#25 0x0000000002123439 clang::Parser::ParseExpression(clang::Parser::TypeCastState) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseExpr.cpp:127:10
#26 0x000000000218c8e5 clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseStmt.cpp:530:19
#27 0x000000000218aea6 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseStmt.cpp:279:14
#28 0x000000000218a711 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseStmt.cpp:117:20
#29 0x00000000021934c1 clang::Parser::ParseCompoundStatementBody(bool) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseStmt.cpp:1205:11
#30 0x0000000002194a3a clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseStmt.cpp:2467:21
#31 0x00000000020e0fa0 isNot /__w/clangd/clangd/llvm-project/clang/include/clang/Lex/Token.h:99:52
#32 0x00000000020e0fa0 clang::Parser::ParseLexedMethodDef(clang::Parser::LexedMethod&) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseCXXInlineMethods.cpp:600:14
#33 0x00000000020dfc1a clang::Parser::ParseLexedMethodDefs(clang::Parser::ParsingClass&) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseCXXInlineMethods.cpp:529:33
#34 0x0000000002116a1b clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation, clang::SourceLocation, clang::ParsedAttributes&, unsigned int, clang::Decl*) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseDeclCXX.cpp:3669:21
#35 0x0000000002114025 clang::Parser::ParseClassSpecifier(clang::tok::TokenKind, clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext, clang::ParsedAttributes&) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseDeclCXX.cpp:0:7
#36 0x00000000020f4ebe empty /__w/clangd/clangd/llvm-project/llvm/include/llvm/ADT/SmallVector.h:94:46
#37 0x00000000020f4ebe empty /__w/clangd/clangd/llvm-project/clang/include/clang/Sema/ParsedAttr.h:819:40
#38 0x00000000020f4ebe clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*, clang::ImplicitTypenameContext) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseDecl.cpp:4323:23
#39 0x00000000020d7044 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) /__w/clangd/clangd/llvm-project/clang/lib/Parse/Parser.cpp:1123:10
#40 0x00000000020d6db0 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) /__w/clangd/clangd/llvm-project/clang/lib/Parse/Parser.cpp:1225:12
#41 0x00000000020d5f92 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) /__w/clangd/clangd/llvm-project/clang/lib/Parse/Parser.cpp:1040:14
#42 0x000000000210c71b ~AttributePool /__w/clangd/clangd/llvm-project/clang/include/clang/Sema/ParsedAttr.h:704:22
#43 0x000000000210c71b ~ParsedAttributes /__w/clangd/clangd/llvm-project/clang/include/clang/Sema/ParsedAttr.h:920:7
#44 0x000000000210c71b clang::Parser::ParseInnerNamespace(llvm::SmallVector<clang::Parser::InnerNamespaceInfo, 4u> const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseDeclCXX.cpp:263:5
#45 0x000000000210c109 Exit /__w/clangd/clangd/llvm-project/clang/include/clang/Parse/Parser.h:1142:11
#46 0x000000000210c109 clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&, clang::SourceLocation) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseDeclCXX.cpp:242:18
#47 0x00000000020ef0d0 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseDecl.cpp:0:0
#48 0x00000000020d52fa clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) /__w/clangd/clangd/llvm-project/clang/lib/Parse/Parser.cpp:0:3
#49 0x000000000210c71b ~AttributePool /__w/clangd/clangd/llvm-project/clang/include/clang/Sema/ParsedAttr.h:704:22
#50 0x000000000210c71b ~ParsedAttributes /__w/clangd/clangd/llvm-project/clang/include/clang/Sema/ParsedAttr.h:920:7
#51 0x000000000210c71b clang::Parser::ParseInnerNamespace(llvm::SmallVector<clang::Parser::InnerNamespaceInfo, 4u> const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseDeclCXX.cpp:263:5
#52 0x000000000210c81b Exit /__w/clangd/clangd/llvm-project/clang/include/clang/Parse/Parser.h:1142:11
#53 0x000000000210c81b clang::Parser::ParseInnerNamespace(llvm::SmallVector<clang::Parser::InnerNamespaceInfo, 4u> const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseDeclCXX.cpp:286:18
#54 0x000000000210c109 Exit /__w/clangd/clangd/llvm-project/clang/include/clang/Parse/Parser.h:1142:11
#55 0x000000000210c109 clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&, clang::SourceLocation) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseDeclCXX.cpp:242:18
#56 0x00000000020ef0d0 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseDecl.cpp:0:0
#57 0x00000000020d52fa clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) /__w/clangd/clangd/llvm-project/clang/lib/Parse/Parser.cpp:0:3
#58 0x00000000020d3ca7 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) /__w/clangd/clangd/llvm-project/clang/lib/Parse/Parser.cpp:742:12
#59 0x00000000020cf73e clang::ParseAST(clang::Sema&, bool, bool) /__w/clangd/clangd/llvm-project/clang/lib/Parse/ParseAST.cpp:162:5
#60 0x0000000001ea6cdb clang::FrontendAction::Execute() /__w/clangd/clangd/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1063:10
#61 0x00000000015a0cf3 operator bool /__w/clangd/clangd/llvm-project/llvm/include/llvm/Support/Error.h:234:21
#62 0x00000000015a0cf3 clang::clangd::BackgroundIndex::index(clang::tooling::CompileCommand) /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/index/Background.cpp:325:19
#63 0x00000000015a3e62 _M_data /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/basic_string.h:176:28
#64 0x00000000015a3e62 _M_is_local /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/basic_string.h:211:16
#65 0x00000000015a3e62 _M_dispose /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/basic_string.h:220:7
#66 0x00000000015a3e62 ~basic_string /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/basic_string.h:647:9
#67 0x00000000015a3e62 ~CompileCommand /__w/clangd/clangd/llvm-project/clang/include/clang/Tooling/CompilationDatabase.h:44:8
#68 0x00000000015a3e62 operator() /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/index/Background.cpp:168:22
#69 0x00000000015a3e62 std::_Function_handler<void (), clang::clangd::BackgroundIndex::indexFileTask(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)::$_3>::_M_invoke(std::_Any_data const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/std_function.h:316:2
#70 0x00000000015a784f clang::clangd::BackgroundQueue::work(std::function<void ()>) /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/index/BackgroundQueue.cpp:44:25
#71 0x00000000015a231a ~_Function_base /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/std_function.h:275:11
#72 0x00000000015a231a operator() /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/index/Background.cpp:114:27
#73 0x00000000015a231a 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)::$_1>(void*) /__w/clangd/clangd/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:220:12
#74 0x0000000001618a71 operator= /__w/clangd/clangd/llvm-project/llvm/include/llvm/ADT/PointerIntPair.h:48:5
#75 0x0000000001618a71 PunnedPointer /__w/clangd/clangd/llvm-project/llvm/include/llvm/ADT/PointerIntPair.h:37:60
#76 0x0000000001618a71 PointerIntPair /__w/clangd/clangd/llvm-project/llvm/include/llvm/ADT/PointerIntPair.h:86:13
#77 0x0000000001618a71 UniqueFunctionBase /__w/clangd/clangd/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:338:3
#78 0x0000000001618a71 unique_function /__w/clangd/clangd/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:367:3
#79 0x0000000001618a71 operator() /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:103:14
#80 0x0000000001618a71 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:43:11
#81 0x0000000001618a71 __invoke_impl<void, (lambda at /__w/clangd/clangd/llvm-project/llvm/include/llvm/Support/thread.h:42: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/7.5.0/../../../../include/c++/7.5.0/bits/invoke.h:60:14
#82 0x0000000001618a71 __invoke<(lambda at /__w/clangd/clangd/llvm-project/llvm/include/llvm/Support/thread.h:42: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/7.5.0/../../../../include/c++/7.5.0/bits/invoke.h:95:14
#83 0x0000000001618a71 __apply_impl<(lambda at /__w/clangd/clangd/llvm-project/llvm/include/llvm/Support/thread.h:42: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/7.5.0/../../../../include/c++/7.5.0/tuple:1662:14
#84 0x0000000001618a71 apply<(lambda at /__w/clangd/clangd/llvm-project/llvm/include/llvm/Support/thread.h:42: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/7.5.0/../../../../include/c++/7.5.0/tuple:1671:14
#85 0x0000000001618a71 GenericThreadProxy<std::tuple<(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:41:5
#86 0x0000000001618a71 void* llvm::thread::ThreadProxy<std::tuple<clang::clangd::AsyncTaskRunner::runAsync(llvm::Twine const&, llvm::unique_function<void ()>)::$_1>>(void*) /__w/clangd/clangd/llvm-project/llvm/include/llvm/Support/thread.h:55:5
#87 0x00007f229e4f3609 start_thread /build/glibc-SzIz7B/glibc-2.31/nptl/pthread_create.c:478:7
#88 0x00007f229e2b9133 __clone /build/glibc-SzIz7B/glibc-2.31/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:97:0

System information

Output of clangd --version:

clangd version 17.0.3 (https://github.com/llvm/llvm-project 888437e1b60011b8a375dd30928ec925b448da57)
Features: linux+grpc
Platform: x86_64-unknown-linux-gnu

Editor/LSP plugin:

Neovim(v0.10.0-dev-1452+g363e029e7) + mason-lspconfig

Operating system:

Ubuntu 20.04.3 LTS (Focal Fossa)
domwst commented 7 months ago

This problem was fixed by removing both ~/.cache/clangd and <project root>/.cache/clangd. Previously, after removing some of the entries from compile_commands.json, I'd only removed ~/.cache/clangd, which probably caused the problem. However, these actions shouldn't have caused the problem IMO.