Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clangd crashes while parsing C++ header file #114955

Closed
SebastienBini opened this issue Nov 5, 2024 · 5 comments
Closed

Clangd crashes while parsing C++ header file #114955

SebastienBini opened this issue Nov 5, 2024 · 5 comments
Labels
clangd crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@SebastienBini
Copy link

SebastienBini commented Nov 5, 2024

Clangd crashes while reading a header file containing templates and require clauses. Here are the provided logs:

I[09:38:06.922] Built preamble of size 16445280 for file /xxxxxx/Notifier.h version 1 in 1.61 seconds
I[09:38:06.923] --> workspace/semanticTokens/refresh(1)
I[09:38:06.924] Indexing c++23 standard library in the context of /xxxxxx/Notifier.h
I[09:38:06.924] <-- reply(1)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	/xxxxxx/Notifier.h:238:1: current parser token '{'
1.	/xxxxxx/Notifier.h:22:1: parsing namespace 'si'
 #0 0x00007fa24560469b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/xxxxxx/libLLVM.so.18.1+0x7df69b)
 #1 0x00007fa245601c9b (/xxxxxx/libLLVM.so.18.1+0x7dcc9b)
 #2 0x00007fa24492be40 __restore_rt libc_sigaction.c:0:0
 #3 0x00007fa24a447f6e clang::TemplateArgument::isPackExpansion() const (/xxxxxx/libclang-cpp.so.18.1+0x116bf6e)
 #4 0x00007fa24afcfc3e (/xxxxxx/libclang-cpp.so.18.1+0x1cf3c3e)
 #5 0x00007fa24aff4017 (/xxxxxx/libclang-cpp.so.18.1+0x1d18017)
 #6 0x00007fa24affa24e (/xxxxxx/libclang-cpp.so.18.1+0x1d1e24e)
 #7 0x00007fa24affdd65 (/xxxxxx/libclang-cpp.so.18.1+0x1d21d65)
 #8 0x00007fa24affe78b (/xxxxxx/libclang-cpp.so.18.1+0x1d2278b)
 #9 0x00007fa24afef1ad clang::Sema::SubstConstraintExprWithoutSatisfaction(clang::Expr*, clang::MultiLevelTemplateArgumentList const&) (/xxxxxx/libclang-cpp.so.18.1+0x1d131ad)
#10 0x00007fa24a84d4ac (/xxxxxx/libclang-cpp.so.18.1+0x15714ac)
#11 0x00007fa24a84fb9f clang::Sema::AreConstraintExpressionsEqual(clang::NamedDecl const*, clang::Expr const*, clang::Sema::TemplateCompareNewDeclInfo const&, clang::Expr const*) (/xxxxxx/libclang-cpp.so.18.1+0x1573b9f)
#12 0x00007fa24aec0f88 clang::Sema::TemplateParameterListsAreEqual(clang::Sema::TemplateCompareNewDeclInfo const&, clang::TemplateParameterList*, clang::NamedDecl const*, clang::TemplateParameterList*, bool, clang::Sema::TemplateParameterListEqualKind, clang::SourceLocation) (/xxxxxx/libclang-cpp.so.18.1+0x1be4f88)
#13 0x00007fa24adf351e (/xxxxxx/libclang-cpp.so.18.1+0x1b1751e)
#14 0x00007fa24adf3fb9 clang::Sema::CheckOverload(clang::Scope*, clang::FunctionDecl*, clang::LookupResult const&, clang::NamedDecl*&, bool) (/xxxxxx/libclang-cpp.so.18.1+0x1b17fb9)
#15 0x00007fa24a90fa6b clang::Sema::CheckFunctionDeclaration(clang::Scope*, clang::FunctionDecl*, clang::LookupResult&, bool, bool) (/xxxxxx/libclang-cpp.so.18.1+0x1633a6b)
#16 0x00007fa24a91ed72 clang::Sema::ActOnFunctionDeclarator(clang::Scope*, clang::Declarator&, clang::DeclContext*, clang::TypeSourceInfo*, clang::LookupResult&, llvm::MutableArrayRef<clang::TemplateParameterList*>, bool&) (/xxxxxx/libclang-cpp.so.18.1+0x1642d72)
#17 0x00007fa24a9209e9 clang::Sema::HandleDeclarator(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>) (/xxxxxx/libclang-cpp.so.18.1+0x16449e9)
#18 0x00007fa24a9212e5 clang::Sema::ActOnStartOfFunctionDef(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>, clang::Sema::SkipBodyInfo*, clang::Sema::FnBodyKind) (/xxxxxx/libclang-cpp.so.18.1+0x16452e5)
#19 0x00007fa249ecf18e clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/xxxxxx/libclang-cpp.so.18.1+0xbf318e)
#20 0x00007fa249eb5af7 clang::Parser::ParseSingleDeclarationAfterTemplate(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo const&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/xxxxxx/libclang-cpp.so.18.1+0xbd9af7)
#21 0x00007fa249ebd2dc clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/xxxxxx/libclang-cpp.so.18.1+0xbe12dc)
#22 0x00007fa249ebd507 clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/xxxxxx/libclang-cpp.so.18.1+0xbe1507)
#23 0x00007fa249df8c66 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/xxxxxx/libclang-cpp.so.18.1+0xb1cc66)
#24 0x00007fa249ed0dfc clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/xxxxxx/libclang-cpp.so.18.1+0xbf4dfc)
#25 0x00007fa249e0e634 clang::Parser::ParseInnerNamespace(llvm::SmallVector<clang::Parser::InnerNamespaceInfo, 4u> const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) (/xxxxxx/libclang-cpp.so.18.1+0xb32634)
#26 0x00007fa249e0e528 clang::Parser::ParseInnerNamespace(llvm::SmallVector<clang::Parser::InnerNamespaceInfo, 4u> const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) (/xxxxxx/libclang-cpp.so.18.1+0xb32528)
#27 0x00007fa249e122cf clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&, clang::SourceLocation) (/xxxxxx/libclang-cpp.so.18.1+0xb362cf)
#28 0x00007fa249df8e58 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/xxxxxx/libclang-cpp.so.18.1+0xb1ce58)
#29 0x00007fa249ed0dfc clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/xxxxxx/libclang-cpp.so.18.1+0xbf4dfc)
#30 0x00007fa249ed2665 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/xxxxxx/libclang-cpp.so.18.1+0xbf6665)
#31 0x00007fa249ed2b2f clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/xxxxxx/libclang-cpp.so.18.1+0xbf6b2f)
#32 0x00007fa249dc86db clang::ParseAST(clang::Sema&, bool, bool) (/xxxxxx/libclang-cpp.so.18.1+0xaec6db)
#33 0x00007fa24bef51f1 clang::FrontendAction::Execute() (/xxxxxx/libclang-cpp.so.18.1+0x2c191f1)
#34 0x000056366968e5c5 (/xxxxxx/clangd+0x7ee5c5)
#35 0x000056366970af87 (/xxxxxx/clangd+0x86af87)
#36 0x000056366970b945 (/xxxxxx/clangd+0x86b945)
#37 0x0000563669703c1a (/xxxxxx/clangd+0x863c1a)
#38 0x000056366970462b (/xxxxxx/clangd+0x86462b)
#39 0x00005636698cca7e (/xxxxxx/clangd+0xa2ca7e)
#40 0x00007fa24497565b start_thread pthread_create.c:0:0
#41 0x00007fa2449f2990 __clone (/xxxxxx/libc.so.6+0xfe990)
Signalled during AST worker action: Build AST
  Filename: /xxxxxx/Notifier.h
  Directory: /xxxxxx
  Command Line: xxxxxx
  Version: 1
[Error - 9:38:08 AM] The Clang Language Server server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.

And the version:

> clangd --version                                                                                                                                                                                                                                  9:45
clangd version 18.1.7
Features: linux
Platform: xxxxxx

And here is a snippet of the file near line 238 (template member function definition of a template class):

template <class... Args>
template <class BaseHandle_t, class T, class Functor>
XXX_REQUIRES(std::invocable<Functor const, std::shared_ptr<T>, Args...>)
NotifierSubscriptionPtr Notifier<Args...>::Impl::Subscribe(
    Ptr_t const& ioSelf, std::shared_ptr<T> const& iObj, Functor iFunc)
{ // line 238

with #define XXX_REQUIRES(...) requires __VA_ARGS__

The code compiles fine with g++. But clang++ crashes when it has to read this file, with the same stack as clangd.

Thank you!

@EugeneZelenko EugeneZelenko added clangd crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels Nov 5, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 5, 2024

@llvm/issue-subscribers-clangd

Author: Sébastien BINI (SebastienBini)

Clangd crashes while reading a header file containing templates and require clauses. Here are the provided logs:
I[09:38:06.922] Built preamble of size 16445280 for file /xxxxxx/Notifier.h version 1 in 1.61 seconds
I[09:38:06.923] --&gt; workspace/semanticTokens/refresh(1)
I[09:38:06.924] Indexing c++23 standard library in the context of /xxxxxx/Notifier.h
I[09:38:06.924] &lt;-- reply(1)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	/xxxxxx/Notifier.h:238:1: current parser token '{'
1.	/xxxxxx/Notifier.h:22:1: parsing namespace 'si'
 #<!-- -->0 0x00007fa24560469b llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (/xxxxxx/libLLVM.so.18.1+0x7df69b)
 #<!-- -->1 0x00007fa245601c9b (/xxxxxx/libLLVM.so.18.1+0x7dcc9b)
 #<!-- -->2 0x00007fa24492be40 __restore_rt libc_sigaction.c:0:0
 #<!-- -->3 0x00007fa24a447f6e clang::TemplateArgument::isPackExpansion() const (/xxxxxx/libclang-cpp.so.18.1+0x116bf6e)
 #<!-- -->4 0x00007fa24afcfc3e (/xxxxxx/libclang-cpp.so.18.1+0x1cf3c3e)
 #<!-- -->5 0x00007fa24aff4017 (/xxxxxx/libclang-cpp.so.18.1+0x1d18017)
 #<!-- -->6 0x00007fa24affa24e (/xxxxxx/libclang-cpp.so.18.1+0x1d1e24e)
 #<!-- -->7 0x00007fa24affdd65 (/xxxxxx/libclang-cpp.so.18.1+0x1d21d65)
 #<!-- -->8 0x00007fa24affe78b (/xxxxxx/libclang-cpp.so.18.1+0x1d2278b)
 #<!-- -->9 0x00007fa24afef1ad clang::Sema::SubstConstraintExprWithoutSatisfaction(clang::Expr*, clang::MultiLevelTemplateArgumentList const&amp;) (/xxxxxx/libclang-cpp.so.18.1+0x1d131ad)
#<!-- -->10 0x00007fa24a84d4ac (/xxxxxx/libclang-cpp.so.18.1+0x15714ac)
#<!-- -->11 0x00007fa24a84fb9f clang::Sema::AreConstraintExpressionsEqual(clang::NamedDecl const*, clang::Expr const*, clang::Sema::TemplateCompareNewDeclInfo const&amp;, clang::Expr const*) (/xxxxxx/libclang-cpp.so.18.1+0x1573b9f)
#<!-- -->12 0x00007fa24aec0f88 clang::Sema::TemplateParameterListsAreEqual(clang::Sema::TemplateCompareNewDeclInfo const&amp;, clang::TemplateParameterList*, clang::NamedDecl const*, clang::TemplateParameterList*, bool, clang::Sema::TemplateParameterListEqualKind, clang::SourceLocation) (/xxxxxx/libclang-cpp.so.18.1+0x1be4f88)
#<!-- -->13 0x00007fa24adf351e (/xxxxxx/libclang-cpp.so.18.1+0x1b1751e)
#<!-- -->14 0x00007fa24adf3fb9 clang::Sema::CheckOverload(clang::Scope*, clang::FunctionDecl*, clang::LookupResult const&amp;, clang::NamedDecl*&amp;, bool) (/xxxxxx/libclang-cpp.so.18.1+0x1b17fb9)
#<!-- -->15 0x00007fa24a90fa6b clang::Sema::CheckFunctionDeclaration(clang::Scope*, clang::FunctionDecl*, clang::LookupResult&amp;, bool, bool) (/xxxxxx/libclang-cpp.so.18.1+0x1633a6b)
#<!-- -->16 0x00007fa24a91ed72 clang::Sema::ActOnFunctionDeclarator(clang::Scope*, clang::Declarator&amp;, clang::DeclContext*, clang::TypeSourceInfo*, clang::LookupResult&amp;, llvm::MutableArrayRef&lt;clang::TemplateParameterList*&gt;, bool&amp;) (/xxxxxx/libclang-cpp.so.18.1+0x1642d72)
#<!-- -->17 0x00007fa24a9209e9 clang::Sema::HandleDeclarator(clang::Scope*, clang::Declarator&amp;, llvm::MutableArrayRef&lt;clang::TemplateParameterList*&gt;) (/xxxxxx/libclang-cpp.so.18.1+0x16449e9)
#<!-- -->18 0x00007fa24a9212e5 clang::Sema::ActOnStartOfFunctionDef(clang::Scope*, clang::Declarator&amp;, llvm::MutableArrayRef&lt;clang::TemplateParameterList*&gt;, clang::Sema::SkipBodyInfo*, clang::Sema::FnBodyKind) (/xxxxxx/libclang-cpp.so.18.1+0x16452e5)
#<!-- -->19 0x00007fa249ecf18e clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&amp;, clang::Parser::ParsedTemplateInfo const&amp;, clang::Parser::LateParsedAttrList*) (/xxxxxx/libclang-cpp.so.18.1+0xbf318e)
#<!-- -->20 0x00007fa249eb5af7 clang::Parser::ParseSingleDeclarationAfterTemplate(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo const&amp;, clang::ParsingDeclRAIIObject&amp;, clang::SourceLocation&amp;, clang::ParsedAttributes&amp;, clang::AccessSpecifier) (/xxxxxx/libclang-cpp.so.18.1+0xbd9af7)
#<!-- -->21 0x00007fa249ebd2dc clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&amp;, clang::ParsedAttributes&amp;, clang::AccessSpecifier) (/xxxxxx/libclang-cpp.so.18.1+0xbe12dc)
#<!-- -->22 0x00007fa249ebd507 clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, clang::SourceLocation&amp;, clang::ParsedAttributes&amp;, clang::AccessSpecifier) (/xxxxxx/libclang-cpp.so.18.1+0xbe1507)
#<!-- -->23 0x00007fa249df8c66 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&amp;, clang::ParsedAttributes&amp;, clang::ParsedAttributes&amp;, clang::SourceLocation*) (/xxxxxx/libclang-cpp.so.18.1+0xb1cc66)
#<!-- -->24 0x00007fa249ed0dfc clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&amp;, clang::ParsedAttributes&amp;, clang::ParsingDeclSpec*) (/xxxxxx/libclang-cpp.so.18.1+0xbf4dfc)
#<!-- -->25 0x00007fa249e0e634 clang::Parser::ParseInnerNamespace(llvm::SmallVector&lt;clang::Parser::InnerNamespaceInfo, 4u&gt; const&amp;, unsigned int, clang::SourceLocation&amp;, clang::ParsedAttributes&amp;, clang::BalancedDelimiterTracker&amp;) (/xxxxxx/libclang-cpp.so.18.1+0xb32634)
#<!-- -->26 0x00007fa249e0e528 clang::Parser::ParseInnerNamespace(llvm::SmallVector&lt;clang::Parser::InnerNamespaceInfo, 4u&gt; const&amp;, unsigned int, clang::SourceLocation&amp;, clang::ParsedAttributes&amp;, clang::BalancedDelimiterTracker&amp;) (/xxxxxx/libclang-cpp.so.18.1+0xb32528)
#<!-- -->27 0x00007fa249e122cf clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&amp;, clang::SourceLocation) (/xxxxxx/libclang-cpp.so.18.1+0xb362cf)
#<!-- -->28 0x00007fa249df8e58 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&amp;, clang::ParsedAttributes&amp;, clang::ParsedAttributes&amp;, clang::SourceLocation*) (/xxxxxx/libclang-cpp.so.18.1+0xb1ce58)
#<!-- -->29 0x00007fa249ed0dfc clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&amp;, clang::ParsedAttributes&amp;, clang::ParsingDeclSpec*) (/xxxxxx/libclang-cpp.so.18.1+0xbf4dfc)
#<!-- -->30 0x00007fa249ed2665 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&lt;clang::DeclGroupRef&gt;&amp;, clang::Sema::ModuleImportState&amp;) (/xxxxxx/libclang-cpp.so.18.1+0xbf6665)
#<!-- -->31 0x00007fa249ed2b2f clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr&lt;clang::DeclGroupRef&gt;&amp;, clang::Sema::ModuleImportState&amp;) (/xxxxxx/libclang-cpp.so.18.1+0xbf6b2f)
#<!-- -->32 0x00007fa249dc86db clang::ParseAST(clang::Sema&amp;, bool, bool) (/xxxxxx/libclang-cpp.so.18.1+0xaec6db)
#<!-- -->33 0x00007fa24bef51f1 clang::FrontendAction::Execute() (/xxxxxx/libclang-cpp.so.18.1+0x2c191f1)
#<!-- -->34 0x000056366968e5c5 (/xxxxxx/clangd+0x7ee5c5)
#<!-- -->35 0x000056366970af87 (/xxxxxx/clangd+0x86af87)
#<!-- -->36 0x000056366970b945 (/xxxxxx/clangd+0x86b945)
#<!-- -->37 0x0000563669703c1a (/xxxxxx/clangd+0x863c1a)
#<!-- -->38 0x000056366970462b (/xxxxxx/clangd+0x86462b)
#<!-- -->39 0x00005636698cca7e (/xxxxxx/clangd+0xa2ca7e)
#<!-- -->40 0x00007fa24497565b start_thread pthread_create.c:0:0
#<!-- -->41 0x00007fa2449f2990 __clone (/xxxxxx/libc.so.6+0xfe990)
Signalled during AST worker action: Build AST
  Filename: /xxxxxx/Notifier.h
  Directory: /xxxxxx
  Command Line: xxxxxx
  Version: 1
[Error - 9:38:08 AM] The Clang Language Server server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.

And the version:

&gt; clangd --version                                                                                                                                                                                                                                  9:45
clangd version 18.1.7
Features: linux
Platform: xxxxxx

And here is a snippet of the file near line 238 (template member function definition of a template class):

template &lt;class... Args&gt;
template &lt;class BaseHandle_t, class T, class Functor&gt;
XXX_REQUIRES(std::invocable&lt;Functor const, std::shared_ptr&lt;T&gt;, Args...&gt;)
NotifierSubscriptionPtr Notifier&lt;Args...&gt;::Impl::Subscribe(
    Ptr_t const&amp; ioSelf, std::shared_ptr&lt;T&gt; const&amp; iObj, Functor iFunc)
{ // line 238

with #define XXX_REQUIRES(...) requires __VA_ARGS__

The code compiles fine with g++. But clang++ crashes when it has to read this file, with the same stack as clangd.

Thank you!

@EugeneZelenko
Copy link
Contributor

Could you please try 19 or main branch?

@SebastienBini
Copy link
Author

The file compiles with version 19.1.1

@EugeneZelenko
Copy link
Contributor

Only most recent release is maintained.

@SebastienBini
Copy link
Author

I guess the issue can be closed then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clangd crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
None yet
Development

No branches or pull requests

3 participants