Skip to content

ICE on code with constevals #53244

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
Fedr opened this issue Jan 17, 2022 · 7 comments
Closed

ICE on code with constevals #53244

Fedr opened this issue Jan 17, 2022 · 7 comments
Labels
bug Indicates an unexpected problem or unintended behavior c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" consteval C++20 consteval crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@Fedr
Copy link

Fedr commented Jan 17, 2022

This program compilation results in ICE:

struct A {       
    consteval A() {}
    A(const A&) = delete;
    consteval void f() {}
};

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

Demo: https://gcc.godbolt.org/z/rx7js6WrK
Edit: Reduce: https://godbolt.org/z/7rv8b8YxG

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++ -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 -Wall -Wextra -pedantic-errors <source>
1.	<eof> parser at end of file
2.	<source>:7:12: parsing function body 'main'
 #0 0x000055f90a339c2f PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x000055f90a337b00 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3537b00)
 #2 0x000055f90a272788 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007fbd7c5fd3c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
 #4 0x000055f90cdbb6a8 clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::VoidExprEvaluator, bool>::Visit(clang::Stmt const*) ExprConstant.cpp:0:0
 #5 0x000055f90cdbca4d clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::VoidExprEvaluator, bool>::Visit(clang::Stmt const*) ExprConstant.cpp:0:0
 #6 0x000055f90cd74a94 Evaluate(clang::APValue&, (anonymous namespace)::EvalInfo&, clang::Expr const*) ExprConstant.cpp:0:0
 #7 0x000055f90cd8b326 EvaluateInPlace(clang::APValue&, (anonymous namespace)::EvalInfo&, (anonymous namespace)::LValue const&, clang::Expr const*, bool) ExprConstant.cpp:0:0
 #8 0x000055f90cd92fec clang::Expr::EvaluateAsConstantExpr(clang::Expr::EvalResult&, clang::ASTContext const&, clang::Expr::ConstantExprKind) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5f92fec)
 #9 0x000055f90c509e19 clang::Sema::PopExpressionEvaluationContext() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5709e19)
#10 0x000055f90c3b9990 clang::Sema::ActOnFinishFunctionBody(clang::Decl*, clang::Stmt*, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x55b9990)
#11 0x000055f90c1e1827 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x53e1827)
#12 0x000055f90c136d64 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5336d64)
#13 0x000055f90c15ffcc clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x535ffcc)
#14 0x000055f90c131df9 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5331df9)
#15 0x000055f90c132501 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.280) Parser.cpp:0:0
#16 0x000055f90c138429 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5338429)
#17 0x000055f90c139849 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5339849)
#18 0x000055f90c12d0a9 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x532d0a9)
#19 0x000055f90b2bae72 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x44bae72)
#20 0x000055f90acb9fd1 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3eb9fd1)
#21 0x000055f90ac55532 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3e55532)
#22 0x000055f90ad836f3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3f836f3)
#23 0x000055f907f7c03c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x117c03c)
#24 0x000055f907f781fd ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#25 0x000055f90aaf4dd5 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
#26 0x000055f90a272d73 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3472d73)
#27 0x000055f90aaf6ea8 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-trunk/bin/clang+++0x3cf6ea8)
#28 0x000055f90aacb90a clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3ccb90a)
#29 0x000055f90aacc44f clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3ccc44f)
#30 0x000055f90aad4d45 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3cd4d45)
#31 0x000055f907e8a232 main (/opt/compiler-explorer/clang-trunk/bin/clang+++0x108a232)
#32 0x00007fbd7c0ad0b3 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b3)
#33 0x000055f907f77d7a _start (/opt/compiler-explorer/clang-trunk/bin/clang+++0x1177d7a)
clang-14: error: clang frontend command failed with exit code 139 (use -v to see invocation)
ASM generation compiler returned: 139
@EugeneZelenko EugeneZelenko added bug Indicates an unexpected problem or unintended behavior clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed new issue labels Jan 17, 2022
@llvmbot
Copy link
Member

llvmbot commented Jan 17, 2022

@llvm/issue-subscribers-clang-frontend

@llvmbot
Copy link
Member

llvmbot commented Jan 17, 2022

@llvm/issue-subscribers-bug

@Izaron
Copy link
Member

Izaron commented Feb 7, 2022

Proposed fix at https://reviews.llvm.org/D119095

@usx95 usx95 added c++20 crash Prefer [crash-on-valid] or [crash-on-invalid] consteval C++20 consteval labels Aug 20, 2022
@llvmbot
Copy link
Member

llvmbot commented Aug 20, 2022

@llvm/issue-subscribers-c-20

@xgupta
Copy link
Contributor

xgupta commented Jan 25, 2023

Fixed on trunk.

@Fedr
Copy link
Author

Fedr commented Jan 25, 2023

If one removes = delete:

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

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

then Clang trunk still shows an error:

error: call to consteval function 'A::f' is not a constant expression

Online demo: https://gcc.godbolt.org/z/eYTKz6zKh

@AaronBallman
Copy link
Collaborator

There's no definition of the copy constructor, so the diagnostic makes sense in that regard. However, it looks like Clang is missing a copy elision during constant evaluation: https://gcc.godbolt.org/z/Yj4bvon3f (note how the non-consteval variant returns 0 instead of 1 -- runtime execution is eliding the copy constructor but constant evaluation is not). I think this is a separate issue, so I've filed: #60286

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" consteval C++20 consteval crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
Status: Done
Development

No branches or pull requests

7 participants