constexpr void* operator new[](decltype(sizeof(int)), void*p) {
return p;
}
constexpr int f() {
struct X { int a, b[5]; } x = {(new(&x.b) int[5])[1]=12,15};
return x.b[1];
}
static_assert(f() == 12);
clang asserts. clang with -fexperimental-new-constant-interpreter rejects the static_assert. gcc accepts.
clang++: /root/llvm-project/llvm/tools/clang/lib/AST/ExprConstant.cpp:15119: bool {anonymous}::ArrayExprEvaluator::VisitCXXParenListOrInitListExpr(const clang::Expr*, llvm::ArrayRef<clang::Expr*>, const clang::Expr*, clang::QualType): Assertion `(!Result.isArray() || Result.getArrayInitializedElts() == 0) && "zero-initialized array shouldn't have any initialized elts"' 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++ -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 -std=c++2c <source>
1. <eof> parser at end of file
#0 0x000000000455d408 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x455d408)
#1 0x000000000455a234 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x455a234)
#2 0x000000000455a854 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x455a854)
#3 0x00000000044968c8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x00007efad1042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#5 0x00007efad10969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#6 0x00007efad1042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#7 0x00007efad10287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#8 0x00007efad102871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#9 0x00007efad1039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#10 0x000000000825d3b0 (anonymous namespace)::ArrayExprEvaluator::VisitCXXParenListOrInitListExpr(clang::Expr const*, llvm::ArrayRef<clang::Expr*>, clang::Expr const*, clang::QualType) ExprConstant.cpp:0:0
#11 0x000000000825ab7d clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::ArrayExprEvaluator, bool>::Visit(clang::Stmt const*) ExprConstant.cpp:0:0
#12 0x000000000825b6ec EvaluateArray(clang::Expr const*, (anonymous namespace)::LValue const&, clang::APValue&, (anonymous namespace)::EvalInfo&) ExprConstant.cpp:0:0
#13 0x000000000825b809 EvaluateInPlace(clang::APValue&, (anonymous namespace)::EvalInfo&, (anonymous namespace)::LValue const&, clang::Expr const*, bool) (.part.0) ExprConstant.cpp:0:0
#14 0x0000000008286b24 (anonymous namespace)::RecordExprEvaluator::VisitCXXParenListOrInitListExpr(clang::Expr const*, llvm::ArrayRef<clang::Expr*>) ExprConstant.cpp:0:0
#15 0x000000000825837c clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::RecordExprEvaluator, bool>::Visit(clang::Stmt const*) ExprConstant.cpp:0:0
#16 0x0000000008259126 EvaluateRecord(clang::Expr const*, (anonymous namespace)::LValue const&, clang::APValue&, (anonymous namespace)::EvalInfo&) ExprConstant.cpp:0:0
#17 0x000000000825b7c7 EvaluateInPlace(clang::APValue&, (anonymous namespace)::EvalInfo&, (anonymous namespace)::LValue const&, clang::Expr const*, bool) (.part.0) ExprConstant.cpp:0:0
#18 0x000000000825f721 EvaluateVarDecl((anonymous namespace)::EvalInfo&, clang::VarDecl const*) (.part.0) ExprConstant.cpp:0:0
#19 0x000000000825f8db EvaluateDecl((anonymous namespace)::EvalInfo&, clang::Decl const*, bool) ExprConstant.cpp:0:0
#20 0x0000000008260baf EvaluateStmt((anonymous namespace)::StmtResult&, (anonymous namespace)::EvalInfo&, clang::Stmt const*, clang::SwitchCase const*) (.part.0) ExprConstant.cpp:0:0
#21 0x0000000008260c78 EvaluateStmt((anonymous namespace)::StmtResult&, (anonymous namespace)::EvalInfo&, clang::Stmt const*, clang::SwitchCase const*) (.part.0) ExprConstant.cpp:0:0
#22 0x000000000826673b HandleFunctionCall(clang::SourceLocation, clang::FunctionDecl const*, (anonymous namespace)::LValue const*, clang::Expr const*, llvm::ArrayRef<clang::Expr const*>, (anonymous namespace)::CallRef, clang::Stmt const*, (anonymous namespace)::EvalInfo&, clang::APValue&, (anonymous namespace)::LValue const*) ExprConstant.cpp:0:0
#23 0x00000000082caff8 (anonymous namespace)::IntExprEvaluator::VisitCallExpr(clang::CallExpr const*) ExprConstant.cpp:0:0
#24 0x000000000823de30 clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::IntExprEvaluator, bool>::Visit(clang::Stmt const*) ExprConstant.cpp:0:0
#25 0x0000000008268a6f Evaluate(clang::APValue&, (anonymous namespace)::EvalInfo&, clang::Expr const*) ExprConstant.cpp:0:0
#26 0x0000000008269802 EvaluateAsRValue((anonymous namespace)::EvalInfo&, clang::Expr const*, clang::APValue&) ExprConstant.cpp:0:0
#27 0x000000000826df8f clang::Expr::isCXX11ConstantExpr(clang::ASTContext const&, clang::APValue*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x826df8f)
#28 0x000000000826e3b0 EvaluateCPlusPlus11IntegralConstantExpr(clang::ASTContext const&, clang::Expr const*, llvm::APSInt*) ExprConstant.cpp:0:0
#29 0x0000000008272351 clang::Expr::getIntegerConstantExpr(clang::ASTContext const&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x8272351)
#30 0x0000000007118cc5 AnalyzeImplicitConversions(clang::Sema&, clang::Expr*, clang::SourceLocation, bool) (.constprop.0) SemaChecking.cpp:0:0
#31 0x00000000071199d5 clang::Sema::CheckCompletedExpr(clang::Expr*, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71199d5)
#32 0x00000000074ca4a7 clang::Sema::ActOnFinishFullExpr(clang::Expr*, clang::SourceLocation, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x74ca4a7)
#33 0x00000000073141c1 clang::Sema::BuildStaticAssertDeclaration(clang::SourceLocation, clang::Expr*, clang::Expr*, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x73141c1)
#34 0x0000000006ef209b clang::Parser::ParseStaticAssertDeclaration(clang::SourceLocation&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ef209b)
#35 0x0000000006ee0596 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ee0596)
#36 0x0000000006e9c576 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e9c576)
#37 0x0000000006e9d465 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e9d465)
#38 0x0000000006e7e34a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6e7e34a)
#39 0x0000000005073538 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5073538)
#40 0x0000000005394f05 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5394f05)
#41 0x00000000053139e8 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x53139e8)
#42 0x00000000054915bd clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x54915bd)
#43 0x0000000000df32bb cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdf32bb)
#44 0x0000000000de9c1a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#45 0x0000000000de9d9d int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::'lambda'(llvm::SmallVectorImpl<char const*>&)>(long, llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#46 0x00000000050dd5b9 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
#47 0x0000000004496d04 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4496d04)
#48 0x00000000050ddbe6 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
#49 0x000000000509c3c2 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x509c3c2)
#50 0x000000000509d36e 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+++0x509d36e)
#51 0x00000000050a5015 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x50a5015)
#52 0x0000000000def644 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdef644)
#53 0x0000000000ca650a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xca650a)
#54 0x00007efad1029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#55 0x00007efad1029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#56 0x0000000000de96b5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xde96b5)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134
clang asserts. clang with -fexperimental-new-constant-interpreter rejects the static_assert. gcc accepts.
(I think the -fexperimental-new-constant-interpreter behavior is correct?)
https://godbolt.org/z/EPxTbM6hr
Crash trace: