emacs-lsp / lsp-mode

Emacs client/library for the Language Server Protocol
https://emacs-lsp.github.io/lsp-mode
GNU General Public License v3.0
4.72k stars 861 forks source link

LSP-clangd repeatedly crash after loading pytorch source code #4422

Closed xushijie closed 2 months ago

xushijie commented 2 months ago

Thank you for the bug report

Bug description

After build pytorch with option USE_CUDA=0 and USE_CUDNN=0, I load the source code into emacs and found the clangd repeatedly crash during code navigation. The screenshot is: image

The stack(filtered) print in the lsp stderr is:

I[11:01:48.518] Indexed /opt/pytorch/third_party/XNNPACK/src/f32-vbinary/gen/f32-vmulc-minmax-avx512f-u32.c (1 symbols, 8787 refs, 110 files)
I[11:01:48.526] --> $/progress
I[11:01:48.526] --> $/progress
I[11:01:48.568] Indexed /opt/pytorch/third_party/XNNPACK/src/f32-qc8w-gemm/gen/f32-qc8w-gemm-3x16-minmax-avx-broadcast.c (1 symbols, 10334 refs, 109 files)
I[11:01:48.572] --> $/progress
I[11:01:48.572] --> $/progress
I[11:01:48.674] <-- textDocument/codeAction(13)
I[11:01:48.674] --> reply:textDocument/codeAction(13) 0 ms
I[11:01:48.674] <-- textDocument/documentLink(14)
I[11:01:48.675] --> reply:textDocument/documentLink(14) 1 ms
/lib/x86_64-linux-gnu/libLLVM-12.so.1(llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)+0x31)[0x7fb98f1dc2a1]
/lib/x86_64-linux-gnu/libLLVM-12.so.1(llvm::sys::RunSignalHandlers()+0x22)[0x7fb98f1da3a2]
/lib/x86_64-linux-gnu/libLLVM-12.so.1(+0xd739ad)[0x7fb98f1dc9ad]
/lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7fb98df4d520]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Expr::IgnoreImpCasts()+0x1c)[0x7fb994f28d9c]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(+0x13ba2a5)[0x7fb9956df2a5]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Sema::ActOnOpenMPSimdDirective(llvm::ArrayRef<clang::OMPClause*>, clang::Stmt*, clang::SourceLocation, clang::SourceLocation, llvm::SmallDenseMap<clang::ValueDecl const*, clang::Expr const*, 4u, llvm::DenseMapInfo<clang::ValueDecl const*>, llvm::detail::DenseMapPair<clang::ValueDecl const*, clang::Expr const*> >&)+0x1c4)[0x7fb9956ce0b4]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Sema::ActOnOpenMPExecutableDirective(llvm::omp::Directive, clang::DeclarationNameInfo const&, llvm::omp::Directive, llvm::ArrayRef<clang::OMPClause*>, clang::Stmt*, clang::SourceLocation, clang::SourceLocation)+0xc63)[0x7fb9956c68a3]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseOpenMPDeclarativeOrExecutableDirective(clang::Parser::ParsedStmtContext)+0xf58)[0x7fb994d14568]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&)+0x1276)[0x7fb994d2ef06]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*)+0xcd)[0x7fb994d2db0d]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseCompoundStatementBody(bool)+0x650)[0x7fb994d35c70]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&)+0x8a6)[0x7fb994d2e536]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*)+0xcd)[0x7fb994d2db0d]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseIfStatement(clang::SourceLocation*)+0x475)[0x7fb994d30d55]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&)+0x37f)[0x7fb994d2e00f]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*)+0xcd)[0x7fb994d2db0d]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseCompoundStatementBody(bool)+0x650)[0x7fb994d35c70]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&)+0x8a6)[0x7fb994d2e536]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*)+0xcd)[0x7fb994d2db0d]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseForStatement(clang::SourceLocation*)+0x19e7)[0x7fb994d33807]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&)+0x598)[0x7fb994d2e228]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*)+0xcd)[0x7fb994d2db0d]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseCompoundStatementBody(bool)+0x650)[0x7fb994d35c70]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseLambdaExpressionAfterIntroducer(clang::LambdaIntroducer&)+0x1954)[0x7fb994ced954]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseLambdaExpression()+0xc5)[0x7fb994ceb015]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*)+0x1838)[0x7fb994cd8c58]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, clang::Parser::TypeCastState, bool, bool*)+0x2f)[0x7fb994cd50cf]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState)+0x83)[0x7fb994cd38a3]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseExpressionList(llvm::SmallVectorImpl<clang::Expr*>&, llvm::SmallVectorImpl<clang::SourceLocation>&, llvm::function_ref<void ()>)+0xfa)[0x7fb994ce3e6a]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr*, true>)+0xfde)[0x7fb994cd619e]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*)+0xcd)[0x7fb994cd74ed]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, clang::Parser::TypeCastState, bool, bool*)+0x2f)[0x7fb994cd50cf]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState)+0x83)[0x7fb994cd38a3]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseExpression(clang::Parser::TypeCastState)+0x9)[0x7fb994cd3809]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext)+0x46)[0x7fb994d2f8f6]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&)+0xc4f)[0x7fb994d2e8df]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*)+0xcd)[0x7fb994d2db0d]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseCompoundStatementBody(bool)+0x650)[0x7fb994d35c70]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&)+0xb0)[0x7fb994d36b90]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*)+0xb33)[0x7fb994d4fea3]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*)+0x10d0)[0x7fb994caa6f0]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier)+0x34d)[0x7fb994d4f0cd]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier)+0x190)[0x7fb994d4eac0]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*)+0x8e5)[0x7fb994d4dbb5]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseInnerNamespace(llvm::SmallVector<clang::Parser::InnerNamespaceInfo, 4u> const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&)+0x10b)[0x7fb994cbe92b]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&, clang::SourceLocation)+0x1b84)[0x7fb994cbe4a4]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&, clang::SourceLocation*)+0x3e0)[0x7fb994ca42f0]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*)+0xba)[0x7fb994d4d38a]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseInnerNamespace(llvm::SmallVector<clang::Parser::InnerNamespaceInfo, 4u> const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&)+0x10b)[0x7fb994cbe92b]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&, clang::SourceLocation)+0x1b84)[0x7fb994cbe4a4]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&, clang::SourceLocation*)+0x3e0)[0x7fb994ca42f0]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*)+0xba)[0x7fb994d4d38a]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseInnerNamespace(llvm::SmallVector<clang::Parser::InnerNamespaceInfo, 4u> const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&)+0x10b)[0x7fb994cbe92b]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&, clang::SourceLocation)+0x1b84)[0x7fb994cbe4a4]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&, clang::SourceLocation*)+0x3e0)[0x7fb994ca42f0]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*)+0xba)[0x7fb994d4d38a]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool)+0x514)[0x7fb994d4c324]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::ParseAST(clang::Sema&, bool, bool)+0x2fd)[0x7fb994c9374d]
/lib/x86_64-linux-gnu/libclang-cpp.so.12(clang::FrontendAction::Execute()+0x56)[0x7fb9962dd006]
/usr/bin/clangd[0x77d2d6]
/usr/bin/clangd[0x7804a5]
/usr/bin/clangd[0x78450c]
/usr/bin/clangd[0x77edd3]
/usr/bin/clangd[0x8128da]
/lib/x86_64-linux-gnu/libLLVM-12.so.1(+0xd7512f)[0x7fb98f1de12f]
/lib/x86_64-linux-gnu/libc.so.6(+0x94ac3)[0x7fb98df9fac3]
/lib/x86_64-linux-gnu/libc.so.6(+0x126850)[0x7fb98e031850]

Process clangd stderr finished

The lsp-mode version: Status: Installed in ‘lsp-mode-20240408.57/’ (unsigned). Version: 20240408.57 Commit: 5b0198457e4e6570677b3e443cda0ba73d63343b

Steps to reproduce

Refer to the description.. the issue can be reproduced with clean environment: M-x lsp-start-plain.

Expected behavior

The lsp-clangd should not crash during code navigation, and make responses

Which Language Server did you use?

clangd for c source code.

OS

Linux

Error callstack

n/a

Anything else?

n/a

xushijie commented 2 months ago

I close this issue:

  1. Investigation revealed the crash originated from Clangd, not the LSP client. The stack trace confirmed this.
  2. The installed Clangd version was outdated (version 12.0). Upgrading to the latest version (18.x.x) resolved the problem.