Setting std::byte with initializer list is an assertion but not an error/warning
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
### Source
```cpp
#include
void f() {
std::byte b;
b = {3};
}
```
https://godbolt.org/z/9Eacqj5hc
### Crash
```
clang++: /root/llvm-project/llvm/tools/clang/lib/Sema/SemaOverload.cpp:15974: clang::ExprResult clang::Sema::CreateOverloadedBinOp(clang::SourceLocation, clang::BinaryOperatorKind, const clang::UnresolvedSetImpl&, clang::Expr*, clang::Expr*, bool, bool, clang::FunctionDecl*): Assertion `Result.isInvalid() && "C++ binary operator overloading is missing candidates!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -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
1. :5:12: current parser token ';'
2. :3:10: parsing function body 'f'
3. :3:10: in compound statement ('{}')
#0 0x00000000044bc158 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44bc158)
#1 0x00000000044b93b4 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44b93b4)
#2 0x00000000044b99ec llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44b99ec)
#3 0x00000000043f5f48 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x00007b11ad045330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x00007b11ad09ec0c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9ec0c)
#6 0x00007b11ad04527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x00007b11ad0288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x00007b11ad02881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x00007b11ad03b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x00000000077a74de clang::Sema::CreateOverloadedBinOp(clang::SourceLocation, clang::BinaryOperatorKind, clang::UnresolvedSetImpl const&, clang::Expr*, clang::Expr*, bool, bool, clang::FunctionDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x77a74de)
#11 0x0000000007391541 BuildOverloadedBinOp(clang::Sema&, clang::Scope*, clang::SourceLocation, clang::BinaryOperatorKind, clang::Expr*, clang::Expr*) SemaExpr.cpp:0:0
#12 0x00000000073e57c7 clang::Sema::BuildBinOp(clang::Scope*, clang::SourceLocation, clang::BinaryOperatorKind, clang::Expr*, clang::Expr*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x73e57c7)
#13 0x00000000073e5cd5 clang::Sema::ActOnBinOp(clang::Scope*, clang::SourceLocation, clang::tok::TokenKind, clang::Expr*, clang::Expr*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x73e5cd5)
#14 0x0000000006ea225c clang::Parser::ParseRHSOfBinaryExpression(clang::ActionResult, clang::prec::Level) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ea225c)
#15 0x0000000006ea59e9 clang::Parser::ParseExpression(clang::TypoCorrectionTypeBehavior) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ea59e9)
#16 0x0000000006f322b9 clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6f322b9)
#17 0x0000000006f29b9f clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6f29b9f)
#18 0x0000000006f2a516 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::LabelDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6f2a516)
#19 0x0000000006f32a9e clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6f32a9e)
#20 0x0000000006f332ba clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6f332ba)
#21 0x0000000006e2faee clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e2faee)
#22 0x0000000006e79506 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+++0x6e79506)
#23 0x0000000006e23bbb clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e23bbb)
#24 0x0000000006e243af clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e243af)
#25 0x0000000006e30e18 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e30e18)
#26 0x0000000006e31d55 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e31d55)
#27 0x0000000006e0e24a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e0e24a)
#28 0x0000000004fd1998 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fd1998)
#29 0x00000000052f2678 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x52f2678)
#30 0x000000000528028d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x528028d)
#31 0x00000000053c6e9d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x53c6e9d)
#32 0x0000000000d9160c cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd9160c)
#33 0x0000000000d8831a ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#34 0x0000000000d8849d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#35 0x0000000005045c69 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#36 0x00000000043f6344 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43f6344)
#37 0x00000000050467d5 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#38 0x0000000005004c02 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5004c02)
#39 0x0000000005009567 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5009567)
#40 0x0000000005013ac5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5013ac5)
#41 0x0000000000d8db0a clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd8db0a)
#42 0x0000000000ccb4aa main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xccb4aa)
#43 0x00007b11ad02a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#44 0x00007b11ad02a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#45 0x0000000000d87cc5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd87cc5)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Program terminated with signal SIGABRT (6)
Compiler returned: 134
```
### Notes
- This behavior evidently goes back to the introduction of `std::byte` in clang 16, so it's not a recent regression.
- There is no warning or error in a non-assertions build, but it _is_ an error from gcc's perspective, so I'm not sure whether "crash on valid" is true.
Contributor guide
Research direction
Start with clang/lib/Sema/SemaOverload.cpp, especially CreateOverloadedBinOp and the BuildOverloadedBinOp path named in the stack trace. Reproduce the std::byte assignment in an assertions build and compare its behavior with a non-assertions build and GCC. Done means the reproducer no longer triggers the assertion and receives the intended diagnostic behavior.
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
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100