Skip to content

ICE on variadic operator overload #42535

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

Closed
Ralender opened this issue Sep 1, 2019 · 6 comments
Closed

ICE on variadic operator overload #42535

Ralender opened this issue Sep 1, 2019 · 6 comments
Labels
bugzilla Issues migrated from bugzilla c++ clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party crash-on-invalid

Comments

@Ralender
Copy link
Collaborator

Ralender commented Sep 1, 2019

Bugzilla Link 43190
Version trunk
OS Linux
CC @DougGregor,@riccibruno,@zygoloid

Extended Description

the following code makes clang trunk crash.

int f() {
return 0;
}

enum E {};

int operator+ (E, ...) {
return 0;
}

void d() {
int i = E() + &f;
}

example: https://godbolt.org/z/j4F4J3

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@wheatman wheatman added the confirmed Verified by a second party label Jul 15, 2023
@wheatman
Copy link
Contributor

wheatman commented Jul 15, 2023

Was able to simplify the example a little more: https://godbolt.org/z/csMc17qja

class E {};

void operator+ (E, ...) { }

void d() {
  E() + E();
}

it firsts errors that <source>:3:6: error: overloaded 'operator+' cannot be variadic

Assertion:

clang++: /root/llvm-project/clang/include/clang/AST/Decl.h:2629:
clang::ParmVarDecl* clang::FunctionDecl::getParamDecl(unsigned int):
Assertion `i < getNumParams() && "Illegal param #"' failed.

And then crashes with the following dump

<source>:3:6: error: overloaded 'operator+' cannot be variadic
    3 | void operator+ (E, ...) { }
      |      ^
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-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics <source>
1.	<source>:6:12: current parser token ';'
2.	<source>:5:10: parsing function body 'd'
3.	<source>:5:10: in compound statement ('{}')
 #0 0x0000555c232083ba llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x34083ba)
 #1 0x0000555c23206144 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3406144)
 #2 0x0000555c231577c8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007ff1c76cb420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x0000555c259b5b98 clang::InitializedEntity::InitializeParameter(clang::ASTContext&, clang::ParmVarDecl*, clang::QualType) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5bb5b98)
 #5 0x0000555c25b4655f clang::Sema::CreateOverloadedBinOp(clang::SourceLocation, clang::BinaryOperatorKind, clang::UnresolvedSetImpl const&, clang::Expr*, clang::Expr*, bool, bool, clang::FunctionDecl*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5d4655f)
 #6 0x0000555c2580972c BuildOverloadedBinOp(clang::Sema&, clang::Scope*, clang::SourceLocation, clang::BinaryOperatorKind, clang::Expr*, clang::Expr*) SemaExpr.cpp:0:0
 #7 0x0000555c2587db87 clang::Sema::BuildBinOp(clang::Scope*, clang::SourceLocation, clang::BinaryOperatorKind, clang::Expr*, clang::Expr*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5a7db87)
 #8 0x0000555c2587e428 clang::Sema::ActOnBinOp(clang::Scope*, clang::SourceLocation, clang::tok::TokenKind, clang::Expr*, clang::Expr*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5a7e428)
 #9 0x0000555c2544c0bf clang::Parser::ParseRHSOfBinaryExpression(clang::ActionResult<clang::Expr*, true>, clang::prec::Level) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x564c0bf)
#10 0x0000555c2544d6f9 clang::Parser::ParseExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x564d6f9)
#11 0x0000555c254badfd clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x56badfd)
#12 0x0000555c254b15c2 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x56b15c2)
#13 0x0000555c254b1f67 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x56b1f67)
#14 0x0000555c254b2e28 clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x56b2e28)
#15 0x0000555c254b36f3 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x56b36f3)
#16 0x0000555c253fa47a clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x55fa47a)
#17 0x0000555c25426ca9 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5626ca9)
#18 0x0000555c253f4e8e clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x55f4e8e)
#19 0x0000555c253f5936 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.307) Parser.cpp:0:0
#20 0x0000555c253fc39a clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x55fc39a)
#21 0x0000555c253fd63f clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x55fd63f)
#22 0x0000555c253efe7b clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x55efe7b)
#23 0x0000555c2420314d clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x440314d)
#24 0x0000555c23b9d3d1 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3d9d3d1)
#25 0x0000555c23b2f0fa clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3d2f0fa)
#26 0x0000555c23c717b3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3e717b3)
#27 0x0000555c20d18d64 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xf18d64)
#28 0x0000555c20d10cbe ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#29 0x0000555c2399fa99 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
#30 0x0000555c23157c45 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3357c45)
#31 0x0000555c239a2208 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3ba2208)
#32 0x0000555c2396dacb clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3b6dacb)
#33 0x0000555c2396e5c3 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3b6e5c3)
#34 0x0000555c2397542f clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3b7542f)
#35 0x0000555c20d16670 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xf16670)
#36 0x0000555c20c30761 main (/opt/compiler-explorer/clang-trunk/bin/clang+++0xe30761)
#37 0x00007ff1c7179083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#38 0x0000555c20d103fa _start (/opt/compiler-explorer/clang-trunk/bin/clang+++0xf103fa)
clang++: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Compiler returned: 139

@wheatman wheatman added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Jul 15, 2023
@llvmbot
Copy link
Member

llvmbot commented Jul 15, 2023

@llvm/issue-subscribers-clang-frontend

@shafik
Copy link
Collaborator

shafik commented Jul 15, 2023

@wheatman please make sure to use assertions build. if there is an assertion we should note it. I will modify your post accordingly. Also adding the godbolt link as well helps folks following up reproduce quickly.

Assertions are crucial to finding duplicates an assuring we are directing effort to bugs that have come up frequently before.

@shafik
Copy link
Collaborator

shafik commented Jul 15, 2023

CC @Fznamznon

@Endilll
Copy link
Contributor

Endilll commented Jul 15, 2023

@wheatman added crash-on-invalid label

@Fznamznon
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++ clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party crash-on-invalid
Projects
None yet
Development

No branches or pull requests

6 participants