llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.25k stars 12.08k forks source link

[clang] Assertion `ArgIdx < Args.size() && "no argument for this arg conversion"' failed. #115311

Open yijan4845 opened 2 weeks ago

yijan4845 commented 2 weeks ago

This testcase is generated by a fuzzer.

Compiler Explorer: https://godbolt.org/z/T4W7jxvMT

This invalid code will crash on Clang Assertion Trunk.

struct B {};
float &operator++(B);

class b {
  void operator++() = delete;
};
void foo() {
  b bb; ++ bb;
}

It seems that this goes back to clang-18. Maybe related: 88532

Stack dump:

clang++: /root/llvm-project/clang/lib/Sema/SemaOverload.cpp:12547: void CompleteNonViableCandidate(clang::Sema&, clang::OverloadCandidate*, llvm::ArrayRef<clang::Expr*>, clang::OverloadCandidateSet::CandidateSetKind): Assertion `ArgIdx < Args.size() && "no argument for this arg conversion"' 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-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics <source>
1.  <source>:8:14: current parser token ';'
2.  <source>:7:12: parsing function body 'foo'
3.  <source>:7:12: in compound statement ('{}')
 #0 0x0000000003bf66c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3bf66c8)
 #1 0x0000000003bf43cc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3bf43cc)
 #2 0x0000000003b419c8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x0000766161042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007661610969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x0000766161042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007661610287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x000076616102871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x0000766161039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x00000000071c12d4 clang::OverloadCandidateSet::CompleteCandidates(clang::Sema&, clang::OverloadCandidateDisplayKind, llvm::ArrayRef<clang::Expr*>, clang::SourceLocation, llvm::function_ref<bool (clang::OverloadCandidate&)>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71c12d4)
#10 0x00000000071c390e clang::OverloadCandidateSet::NoteCandidates(std::pair<clang::SourceLocation, clang::PartialDiagnostic>, clang::Sema&, clang::OverloadCandidateDisplayKind, llvm::ArrayRef<clang::Expr*>, llvm::StringRef, clang::SourceLocation, llvm::function_ref<bool (clang::OverloadCandidate&)>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71c390e)
#11 0x00000000071c79a2 clang::Sema::CreateOverloadedUnaryOp(clang::SourceLocation, clang::UnaryOperatorKind, clang::UnresolvedSetImpl const&, clang::Expr*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71c79a2)
#12 0x0000000006d21d6d clang::Sema::BuildUnaryOp(clang::Scope*, clang::SourceLocation, clang::UnaryOperatorKind, clang::Expr*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d21d6d)
#13 0x000000000679421b clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x679421b)
#14 0x0000000006794df7 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6794df7)
#15 0x0000000006794e89 clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6794e89)
#16 0x00000000067998a9 clang::Parser::ParseExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x67998a9)
#17 0x000000000681c2e9 clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x681c2e9)
#18 0x00000000068125ce clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x68125ce)
#19 0x0000000006813520 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6813520)
#20 0x00000000068143e4 clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x68143e4)
#21 0x0000000006815b9a clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6815b9a)
#22 0x0000000006729ae3 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6729ae3)
#23 0x000000000675e1fd clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x675e1fd)
#24 0x000000000671d82e clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x671d82e)
#25 0x000000000671dfee clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x671dfee)
#26 0x0000000006725783 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6725783)
#27 0x000000000672666d clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x672666d)
#28 0x0000000006718b8a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6718b8a)
#29 0x00000000045725c8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x45725c8)
#30 0x000000000482d559 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x482d559)
#31 0x00000000047ac7ce clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47ac7ce)
#32 0x000000000491335e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x491335e)
#33 0x0000000000ce9aff cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xce9aff)
#34 0x0000000000ce17ba ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#35 0x00000000045b57c9 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#36 0x0000000003b41e74 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3b41e74)
#37 0x00000000045b5dbf clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#38 0x000000000457c0ad clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x457c0ad)
#39 0x000000000457d19d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x457d19d)
#40 0x0000000004584555 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4584555)
#41 0x0000000000ce6999 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xce6999)
#42 0x0000000000bb3494 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbb3494)
#43 0x0000766161029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#44 0x0000766161029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#45 0x0000000000ce126e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xce126e)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
llvmbot commented 2 weeks ago

@llvm/issue-subscribers-clang-frontend

Author: Yihan Yang (yijan4845)

**This testcase is generated by a fuzzer.** Compiler Explorer: [https://godbolt.org/z/T4W7jxvMT](https://godbolt.org/z/T4W7jxvMT) This invalid code will crash on Clang Assertion Trunk. ```cpp struct B {}; float &operator++(B); class b { void operator++() = delete; }; void foo() { b bb; ++ bb; } ``` It seems that this goes back to clang-18. Maybe related: [88532](https://github.com/llvm/llvm-project/issues/88532) Stack dump: ``` clang++: /root/llvm-project/clang/lib/Sema/SemaOverload.cpp:12547: void CompleteNonViableCandidate(clang::Sema&, clang::OverloadCandidate*, llvm::ArrayRef<clang::Expr*>, clang::OverloadCandidateSet::CandidateSetKind): Assertion `ArgIdx < Args.size() && "no argument for this arg conversion"' 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-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics <source> 1. <source>:8:14: current parser token ';' 2. <source>:7:12: parsing function body 'foo' 3. <source>:7:12: in compound statement ('{}') #0 0x0000000003bf66c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3bf66c8) #1 0x0000000003bf43cc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3bf43cc) #2 0x0000000003b419c8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0 #3 0x0000766161042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #4 0x00007661610969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc) #5 0x0000766161042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476) #6 0x00007661610287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3) #7 0x000076616102871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b) #8 0x0000766161039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96) #9 0x00000000071c12d4 clang::OverloadCandidateSet::CompleteCandidates(clang::Sema&, clang::OverloadCandidateDisplayKind, llvm::ArrayRef<clang::Expr*>, clang::SourceLocation, llvm::function_ref<bool (clang::OverloadCandidate&)>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71c12d4) #10 0x00000000071c390e clang::OverloadCandidateSet::NoteCandidates(std::pair<clang::SourceLocation, clang::PartialDiagnostic>, clang::Sema&, clang::OverloadCandidateDisplayKind, llvm::ArrayRef<clang::Expr*>, llvm::StringRef, clang::SourceLocation, llvm::function_ref<bool (clang::OverloadCandidate&)>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71c390e) #11 0x00000000071c79a2 clang::Sema::CreateOverloadedUnaryOp(clang::SourceLocation, clang::UnaryOperatorKind, clang::UnresolvedSetImpl const&, clang::Expr*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71c79a2) #12 0x0000000006d21d6d clang::Sema::BuildUnaryOp(clang::Scope*, clang::SourceLocation, clang::UnaryOperatorKind, clang::Expr*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d21d6d) #13 0x000000000679421b clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x679421b) #14 0x0000000006794df7 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6794df7) #15 0x0000000006794e89 clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6794e89) #16 0x00000000067998a9 clang::Parser::ParseExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x67998a9) #17 0x000000000681c2e9 clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x681c2e9) #18 0x00000000068125ce clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x68125ce) #19 0x0000000006813520 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6813520) #20 0x00000000068143e4 clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x68143e4) #21 0x0000000006815b9a clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6815b9a) #22 0x0000000006729ae3 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6729ae3) #23 0x000000000675e1fd clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x675e1fd) #24 0x000000000671d82e clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x671d82e) #25 0x000000000671dfee clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x671dfee) #26 0x0000000006725783 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6725783) #27 0x000000000672666d clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x672666d) #28 0x0000000006718b8a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6718b8a) #29 0x00000000045725c8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x45725c8) #30 0x000000000482d559 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x482d559) #31 0x00000000047ac7ce clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47ac7ce) #32 0x000000000491335e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x491335e) #33 0x0000000000ce9aff cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xce9aff) #34 0x0000000000ce17ba ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0 #35 0x00000000045b57c9 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0 #36 0x0000000003b41e74 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3b41e74) #37 0x00000000045b5dbf clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0 #38 0x000000000457c0ad clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x457c0ad) #39 0x000000000457d19d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x457d19d) #40 0x0000000004584555 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4584555) #41 0x0000000000ce6999 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xce6999) #42 0x0000000000bb3494 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbb3494) #43 0x0000766161029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90) #44 0x0000766161029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40) #45 0x0000000000ce126e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xce126e) clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation) Compiler returned: 134 ```
shafik commented 1 week ago

@Fznamznon git bisect points to 11d1310b57a9f2defb4d65a35b90a69020c52e46 and it seems plausible that the drop_front is problematic.