Skip to content

Assertion failure with consteval initializer-and-call expression #55597

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
kimgr opened this issue May 19, 2022 · 5 comments
Closed

Assertion failure with consteval initializer-and-call expression #55597

kimgr opened this issue May 19, 2022 · 5 comments
Labels
c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" crash Prefer [crash-on-valid] or [crash-on-invalid] duplicate Resolved as duplicate

Comments

@kimgr
Copy link
Contributor

kimgr commented May 19, 2022

I happened to have this on my godbolt starting page (https://godbolt.org/z/7rv8b8YxG):

struct A {
    consteval A() {}
    consteval void f() {}
};

int main() {
    A{}.f();
}

and it fires an assertion in mainline clang with -std=c++20:

# manually line-wrapped to bring assertion to light
clang++: /root/llvm-project/clang/lib/Sema/SemaExprCXX.cpp:1455: clang::ExprResult
clang::Sema::BuildCXXTypeConstructExpr(clang::TypeSourceInfo*, clang::SourceLocation, 
clang::MultiExprArg, clang::SourceLocation, bool): Assertion `(!ListInitialization || (Exprs.size() == 1 && 
isa<InitListExpr>(Exprs[0]))) && "List initialization must have initializer list as expression."' 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 -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 <source>
1.	<eof> parser at end of file
2.	<source>:6:12: parsing function body 'main'
 #0 0x0000561c83b02eef PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x0000561c83b00c54 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3b00c54)
 #2 0x0000561c83a35f68 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f5a151353c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x143c0)
 #4 0x00007f5a14c0203b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4303b)
 #5 0x00007f5a14be1859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x00007f5a14be1729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #7 0x00007f5a14bf3006 (/lib/x86_64-linux-gnu/libc.so.6+0x34006)
 #8 0x0000561c85f409bf clang::Sema::BuildCXXTypeConstructExpr(clang::TypeSourceInfo*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5f409bf)
 #9 0x0000561c85ef1c2f clang::TreeTransform<RemoveNestedImmediateInvocation(clang::Sema&, clang::Sema::ExpressionEvaluationContextRecord&, std::reverse_iterator<llvm::PointerIntPair<clang::ConstantExpr*, 1u, unsigned int, llvm::PointerLikeTypeTraits<clang::ConstantExpr*>, llvm::PointerIntPairInfo<clang::ConstantExpr*, 1u, llvm::PointerLikeTypeTraits<clang::ConstantExpr*>>>*>)::ComplexRemove>::TransformCXXFunctionalCastExpr(clang::CXXFunctionalCastExpr*) SemaExpr.cpp:0:0
#10 0x0000561c85ef3473 clang::TreeTransform<RemoveNestedImmediateInvocation(clang::Sema&, clang::Sema::ExpressionEvaluationContextRecord&, std::reverse_iterator<llvm::PointerIntPair<clang::ConstantExpr*, 1u, unsigned int, llvm::PointerLikeTypeTraits<clang::ConstantExpr*>, llvm::PointerIntPairInfo<clang::ConstantExpr*, 1u, llvm::PointerLikeTypeTraits<clang::ConstantExpr*>>>*>)::ComplexRemove>::TransformMemberExpr(clang::MemberExpr*) SemaExpr.cpp:0:0
#11 0x0000561c85ef0c67 clang::TreeTransform<RemoveNestedImmediateInvocation(clang::Sema&, clang::Sema::ExpressionEvaluationContextRecord&, std::reverse_iterator<llvm::PointerIntPair<clang::ConstantExpr*, 1u, unsigned int, llvm::PointerLikeTypeTraits<clang::ConstantExpr*>, llvm::PointerIntPairInfo<clang::ConstantExpr*, 1u, llvm::PointerLikeTypeTraits<clang::ConstantExpr*>>>*>)::ComplexRemove>::TransformCallExpr(clang::CallExpr*) SemaExpr.cpp:0:0
#12 0x0000561c85e91e83 clang::Sema::PopExpressionEvaluationContext() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e91e83)
#13 0x0000561c85d3f2e7 clang::Sema::ActOnFinishFunctionBody(clang::Decl*, clang::Stmt*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5d3f2e7)
#14 0x0000561c85b74eff clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5b74eff)
#15 0x0000561c85ad2a6d clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5ad2a6d)
#16 0x0000561c85af889f clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5af889f)
#17 0x0000561c85acdfd1 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5acdfd1)
#18 0x0000561c85ace6e1 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.282) Parser.cpp:0:0
#19 0x0000561c85ad3c10 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5ad3c10)
#20 0x0000561c85ad5071 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5ad5071)
#21 0x0000561c85ac907b clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5ac907b)
#22 0x0000561c84b8a340 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b8a340)
#23 0x0000561c84518269 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4518269)
#24 0x0000561c844b161a clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44b161a)
#25 0x0000561c845e0cf3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x45e0cf3)
#26 0x0000561c813c5991 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x13c5991)
#27 0x0000561c813c1799 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#28 0x0000561c84345b45 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#29 0x0000561c83a36553 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3a36553)
#30 0x0000561c84347ed6 clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4347ed6)
#31 0x0000561c84316fca clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4316fca)
#32 0x0000561c84317c5f clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4317c5f)
#33 0x0000561c8432016a clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x432016a)
#34 0x0000561c813076dc main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x13076dc)
#35 0x00007f5a14be30b3 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x240b3)
#36 0x0000561c813c130a _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x13c130a)
clang-15: error: clang frontend command failed with exit code 134 (use -v to see invocation)
ASM generation compiler returned: 134
clang-15: /root/llvm-project/clang/lib/Sema/SemaExprCXX.cpp:1455: clang::ExprResult clang::Sema::BuildCXXTypeConstructExpr(clang::TypeSourceInfo*, clang::SourceLocation, clang::MultiExprArg, clang::SourceLocation, bool): Assertion `(!ListInitialization || (Exprs.size() == 1 && isa<InitListExpr>(Exprs[0]))) && "List initialization must have initializer list as expression."' 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-20220519/bin/clang-15 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -main-file-name example.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debug-info-kind=constructor -dwarf-version=4 -debugger-tuning=gdb -fcoverage-compilation-dir=/app -resource-dir /opt/compiler-explorer/clang-assertions-trunk-20220519/lib/clang/15.0.0 -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.0/../../../../include/c++/13.0.0 -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.0/../../../../include/c++/13.0.0/x86_64-linux-gnu -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.0/../../../../include/c++/13.0.0/backward -internal-isystem /opt/compiler-explorer/clang-assertions-trunk-20220519/lib/clang/15.0.0/include -internal-isystem /usr/local/include -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/13.0.0/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++20 -fdeprecated-macro -fdebug-compilation-dir=/app -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/example-5a320c.o -x c++ <source>
1.	<eof> parser at end of file
2.	<source>:6:12: parsing function body 'main'
 #0 0x000055e3d0b02eef PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x000055e3d0b0095c SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f09d1d103c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x143c0)
 #3 0x00007f09d17dd03b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4303b)
 #4 0x00007f09d17bc859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #5 0x00007f09d17bc729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #6 0x00007f09d17ce006 (/lib/x86_64-linux-gnu/libc.so.6+0x34006)
 #7 0x000055e3d2f409bf clang::Sema::BuildCXXTypeConstructExpr(clang::TypeSourceInfo*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-assertions-trunk-20220519/bin/clang-15+0x5f409bf)
 #8 0x000055e3d2ef1c2f clang::TreeTransform<RemoveNestedImmediateInvocation(clang::Sema&, clang::Sema::ExpressionEvaluationContextRecord&, std::reverse_iterator<llvm::PointerIntPair<clang::ConstantExpr*, 1u, unsigned int, llvm::PointerLikeTypeTraits<clang::ConstantExpr*>, llvm::PointerIntPairInfo<clang::ConstantExpr*, 1u, llvm::PointerLikeTypeTraits<clang::ConstantExpr*>>>*>)::ComplexRemove>::TransformCXXFunctionalCastExpr(clang::CXXFunctionalCastExpr*) SemaExpr.cpp:0:0
 #9 0x000055e3d2ef3473 clang::TreeTransform<RemoveNestedImmediateInvocation(clang::Sema&, clang::Sema::ExpressionEvaluationContextRecord&, std::reverse_iterator<llvm::PointerIntPair<clang::ConstantExpr*, 1u, unsigned int, llvm::PointerLikeTypeTraits<clang::ConstantExpr*>, llvm::PointerIntPairInfo<clang::ConstantExpr*, 1u, llvm::PointerLikeTypeTraits<clang::ConstantExpr*>>>*>)::ComplexRemove>::TransformMemberExpr(clang::MemberExpr*) SemaExpr.cpp:0:0
#10 0x000055e3d2ef0c67 clang::TreeTransform<RemoveNestedImmediateInvocation(clang::Sema&, clang::Sema::ExpressionEvaluationContextRecord&, std::reverse_iterator<llvm::PointerIntPair<clang::ConstantExpr*, 1u, unsigned int, llvm::PointerLikeTypeTraits<clang::ConstantExpr*>, llvm::PointerIntPairInfo<clang::ConstantExpr*, 1u, llvm::PointerLikeTypeTraits<clang::ConstantExpr*>>>*>)::ComplexRemove>::TransformCallExpr(clang::CallExpr*) SemaExpr.cpp:0:0
#11 0x000055e3d2e91e83 clang::Sema::PopExpressionEvaluationContext() (/opt/compiler-explorer/clang-assertions-trunk-20220519/bin/clang-15+0x5e91e83)
#12 0x000055e3d2d3f2e7 clang::Sema::ActOnFinishFunctionBody(clang::Decl*, clang::Stmt*, bool) (/opt/compiler-explorer/clang-assertions-trunk-20220519/bin/clang-15+0x5d3f2e7)
#13 0x000055e3d2b74eff clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk-20220519/bin/clang-15+0x5b74eff)
#14 0x000055e3d2ad2a6d clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk-20220519/bin/clang-15+0x5ad2a6d)
#15 0x000055e3d2af889f clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk-20220519/bin/clang-15+0x5af889f)
#16 0x000055e3d2acdfd1 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk-20220519/bin/clang-15+0x5acdfd1)
#17 0x000055e3d2ace6e1 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.282) Parser.cpp:0:0
#18 0x000055e3d2ad3c10 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk-20220519/bin/clang-15+0x5ad3c10)
#19 0x000055e3d2ad5071 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk-20220519/bin/clang-15+0x5ad5071)
#20 0x000055e3d2ac907b clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk-20220519/bin/clang-15+0x5ac907b)
#21 0x000055e3d1b8a340 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk-20220519/bin/clang-15+0x4b8a340)
#22 0x000055e3d1518269 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk-20220519/bin/clang-15+0x4518269)
#23 0x000055e3d14b161a clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk-20220519/bin/clang-15+0x44b161a)
#24 0x000055e3d15e0cf3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk-20220519/bin/clang-15+0x45e0cf3)
#25 0x000055e3ce3c5991 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk-20220519/bin/clang-15+0x13c5991)
#26 0x000055e3ce3c1799 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#27 0x000055e3ce3060d9 main (/opt/compiler-explorer/clang-assertions-trunk-20220519/bin/clang-15+0x13060d9)
#28 0x00007f09d17be0b3 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x240b3)
#29 0x000055e3ce3c130a _start (/opt/compiler-explorer/clang-assertions-trunk-20220519/bin/clang-15+0x13c130a)
clang-15: error: unable to execute command: Aborted (core dumped)
clang-15: error: clang frontend command failed due to signal (use -v to see invocation)
Execution build compiler returned: 254

I don't have a good idea of what's going on, but I thought I'd report the bad input for testcase inspiration. There seem to be several similar issues open already.

@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels May 19, 2022
@llvmbot
Copy link
Member

llvmbot commented May 19, 2022

@llvm/issue-subscribers-clang-frontend

@kimgr
Copy link
Contributor Author

kimgr commented May 19, 2022

@EugeneZelenko Thanks! Could you also add the c++20 label?

@llvmbot
Copy link
Member

llvmbot commented May 19, 2022

@llvm/issue-subscribers-c-20

@EugeneZelenko
Copy link
Contributor

@kimgr: Done.

@kimgr
Copy link
Contributor Author

kimgr commented May 19, 2022

Oops! I know why I had that example in my godbolt. I experimented with the input from another issue: #53244. Closing this as a duplicate.

@kimgr kimgr closed this as not planned Won't fix, can't repro, duplicate, stale May 19, 2022
@EugeneZelenko EugeneZelenko added the duplicate Resolved as duplicate label May 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" crash Prefer [crash-on-valid] or [crash-on-invalid] duplicate Resolved as duplicate
Projects
None yet
Development

No branches or pull requests

3 participants