llvm / llvm/llvm-project

[clangd][clang] Crash in TryListConversion when performing code completion on rvalue reference to VLA parameter

Open
#208,476 1 comment 0 reactions 0 assignees View on GitHub
clangd crash generated by fuzzer regression:20
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

This input is generated by a fuzzer.
Very likely related to https://github.com/llvm/llvm-project/issues/113088. However, this does not reproduce directly through fsyntax-only.
https://godbolt.org/z/8P875Ys5h
Seems to be introduced since clang20.

```cxx
templatevoid f(int(&&)[N],int);void a(){f<1>({},);}
```

```
-std=c++20 -fsyntax-only -Xclang -code-completion-at=example.cpp:1:62
```

```
clang++: warning: argument unused during compilation: '-S' [-Wunused-command-line-argument]
clang++: /root/llvm-project/clang/lib/Sema/SemaOverload.cpp:5545: clang::ImplicitConversionSequence TryListConversion(clang::Sema&, clang::InitListExpr*, clang::QualType, bool, bool, bool): Assertion `isa(AT) && "Expected incomplete array"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-20.1.0/bin/clang++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-14.2.0 -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 -fsyntax-only -Xclang -code-completion-at=example.cpp:1:62
1. parser at end of file
2. :1:53: parsing function body 'a'
3. :1:53: in compound statement ('{}')
#0 0x0000000003e64af8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x3e64af8)
#1 0x0000000003e627b4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x3e627b4)
#2 0x0000000003daec88 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007f0974845330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#4 0x00007f097489eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
#5 0x00007f097484527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#6 0x00007f09748288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#7 0x00007f097482881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#8 0x00007f097483b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#9 0x00000000071222ef TryListConversion(clang::Sema&, clang::InitListExpr*, clang::QualType, bool, bool, bool) SemaOverload.cpp:0:0
#10 0x000000000712156b TryListConversion(clang::Sema&, clang::InitListExpr*, clang::QualType, bool, bool, bool) SemaOverload.cpp:0:0
#11 0x0000000007122362 TryCopyInitialization(clang::Sema&, clang::Expr*, clang::QualType, bool, bool, bool, bool) SemaOverload.cpp:0:0
#12 0x0000000007124f08 clang::Sema::AddOverloadCandidate(clang::FunctionDecl*, clang::DeclAccessPair, llvm::ArrayRef, clang::OverloadCandidateSet&, bool, bool, bool, bool, clang::CallExpr::ADLCallKind, llvm::MutableArrayRef, clang::OverloadCandidateParamOrder, bool, bool) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x7124f08)
#13 0x000000000712e8fd clang::Sema::AddTemplateOverloadCandidate(clang::FunctionTemplateDecl*, clang::DeclAccessPair, clang::TemplateArgumentListInfo*, llvm::ArrayRef, clang::OverloadCandidateSet&, bool, bool, bool, clang::CallExpr::ADLCallKind, clang::OverloadCandidateParamOrder, bool) (.constprop.1) SemaOverload.cpp:0:0
#14 0x000000000712f05b AddOverloadedCallCandidate(clang::Sema&, clang::DeclAccessPair, clang::TemplateArgumentListInfo*, llvm::ArrayRef, clang::OverloadCandidateSet&, bool, bool) SemaOverload.cpp:0:0
#15 0x000000000712f371 clang::Sema::AddOverloadedCallCandidates(clang::UnresolvedLookupExpr*, llvm::ArrayRef, clang::OverloadCandidateSet&, bool) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x712f371)
#16 0x0000000006b04763 clang::SemaCodeCompletion::ProduceCallSignatureHelp(clang::Expr*, llvm::ArrayRef, clang::SourceLocation) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x6b04763)
#17 0x00000000068b35b9 clang::QualType llvm::function_ref::callback_fn)::'lambda'()>(long) ParseExpr.cpp:0:0
#18 0x00000000068bc706 clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x68bc706)
#19 0x00000000068bc9ee clang::Parser::ParseExpressionList(llvm::SmallVectorImpl&, llvm::function_ref, bool, bool, bool*) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x68bc9ee)
#20 0x00000000068c16cc clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x68c16cc)
#21 0x00000000068ba491 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x68ba491)
#22 0x00000000068bc5f7 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x68bc5f7)
#23 0x00000000068bc689 clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x68bc689)
#24 0x00000000068c11f9 clang::Parser::ParseExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x68c11f9)
#25 0x0000000006945929 clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x6945929)
#26 0x000000000693bc9e clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x693bc9e)
#27 0x000000000693cbf0 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x693cbf0)
#28 0x000000000693dab5 clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x693dab5)
#29 0x000000000693f2ba clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x693f2ba)
#30 0x0000000006850a53 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x6850a53)
#31 0x00000000068856ad clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x68856ad)
#32 0x00000000068447be clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x68447be)
#33 0x0000000006844f79 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x6844f79)
#34 0x000000000684c723 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x684c723)
#35 0x000000000684d5fd clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x684d5fd)
#36 0x000000000683fa5a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x683fa5a)
#37 0x0000000004abdd25 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x4abdd25)
#38 0x0000000004a407de clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x4a407de)
#39 0x0000000004babd8e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x4babd8e)
#40 0x0000000000cfe40f cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0xcfe40f)
#41 0x0000000000cf5e9a ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&) driver.cpp:0:0
#42 0x000000000483e749 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#43 0x0000000003daf134 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x3daf134)
#44 0x000000000483ed3f clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#45 0x0000000004801bad clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x4801bad)
#46 0x0000000004802c2e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x4802c2e)
#47 0x000000000480a765 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0x480a765)
#48 0x0000000000cfb213 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0xcfb213)
#49 0x0000000000bc3694 main (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0xbc3694)
#50 0x00007f097482a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#51 0x00007f097482a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#52 0x0000000000cf5945 _start (/opt/compiler-explorer/clang-assertions-20.1.0/bin/clang+++0xcf5945)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```

Contributor guide

Open the contributing guide

Research direction

Start with clang/lib/Sema/SemaOverload.cpp, especially TryListConversion, and reproduce the supplied C++20 example using the code-completion command shown. Trace the call from SemaCodeCompletion::ProduceCallSignatureHelp and compare the related issue; done means this input no longer triggers the assertion or crashes clang.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.