Closed
Description
The following program results in ICE when compiling with clang with option -std=c++23 -pedantic-errors
(Godbolt link):
Note: The example is incorrect (ill-formed). It can be made well-formed by adding template<class = void>
to vec_cal
.
#include <cstddef>
#include <memory>
#include <vector>
namespace fvs {
template<class T>
struct imm_allocator {
using value_type = T;
using size_type = std::size_t;
using difference_type = std::ptrdiff_t;
consteval T* allocate(size_type n)
{
return std::allocator<T>{}.allocate(n);
}
#if __cpp_lib_allocate_at_least >= 202302L
consteval std::allocation_result<T*> allocate_at_least(size_type n)
{
return std::allocator<T>{}.allocate_at_least(n);
}
#endif // __cpp_lib_allocate_at_least >= 202302L
consteval void deallocate(T* p, size_type n)
{
return std::allocator<T>{}.deallocate(p, n);
}
};
template<class T>
using imm_vector = std::vector<T, imm_allocator<T>>;
}
constexpr bool vec_cal() // This should be an immediate-escalating function.
{
fvs::imm_vector<int> v [[maybe_unused]] (42);
return true;
}
int main()
{
static_assert(vec_cal());
}
Error message:
<source>:36:26: error: call to immediate function 'std::vector<int, fvs::imm_allocator<int>>::vector' is not a constant expression
36 | fvs::imm_vector<int> v [[maybe_unused]] (42);
| ^
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 -std=c++23 -pedantic-errors <source>
1. <source>:40:1: current parser token 'int'
2. <source>:35:1: parsing function body 'vec_cal'
#0 0x00000000033c7468 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x33c7468)
#1 0x00000000033c5594 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x33c5594)
#2 0x00000000033145f8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007f9ab5250420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#4 0x0000000006846726 clang::FormatASTNodeDiagnosticArgument(clang::DiagnosticsEngine::ArgumentKind, long, llvm::StringRef, llvm::StringRef, llvm::ArrayRef<std::pair<clang::DiagnosticsEngine::ArgumentKind, long>>, llvm::SmallVectorImpl<char>&, void*, llvm::ArrayRef<long>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6846726)
#5 0x00000000035c3cf7 clang::Diagnostic::FormatDiagnostic(char const*, char const*, llvm::SmallVectorImpl<char>&) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x35c3cf7)
#6 0x00000000035c4795 clang::Diagnostic::FormatDiagnostic(char const*, char const*, llvm::SmallVectorImpl<char>&) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x35c4795)
#7 0x0000000003ebc66d clang::TextDiagnosticPrinter::HandleDiagnostic(clang::DiagnosticsEngine::Level, clang::Diagnostic const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3ebc66d)
#8 0x00000000035c916c clang::DiagnosticIDs::ProcessDiag(clang::DiagnosticsEngine&) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x35c916c)
#9 0x00000000035bf75b clang::DiagnosticsEngine::EmitCurrentDiagnostic(bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x35bf75b)
#10 0x0000000005b1a1cf clang::Sema::EmitCurrentDiagnostic(unsigned int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5b1a1cf)
#11 0x0000000005b1abf1 clang::Sema::ImmediateDiagBuilder::~ImmediateDiagBuilder() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5b1abf1)
#12 0x0000000005b1b36f clang::Sema::SemaDiagnosticBuilder::~SemaDiagnosticBuilder() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5b1b36f)
#13 0x0000000005dcc2fe clang::Sema::DiagnoseImmediateEscalatingReason(clang::FunctionDecl*)::ImmediateEscalatingExpressionsVisitor::Diag(clang::Expr const*, clang::FunctionDecl const*, bool) SemaDeclCXX.cpp:0:0
#14 0x0000000005e04bf2 clang::RecursiveASTVisitor<clang::Sema::DiagnoseImmediateEscalatingReason(clang::FunctionDecl*)::ImmediateEscalatingExpressionsVisitor>::TraverseCXXConstructExpr(clang::CXXConstructExpr*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*>>>>*) SemaDeclCXX.cpp:0:0
#15 0x0000000005e02752 clang::RecursiveASTVisitor<clang::Sema::DiagnoseImmediateEscalatingReason(clang::FunctionDecl*)::ImmediateEscalatingExpressionsVisitor>::dataTraverseNode(clang::Stmt*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*>>>>*) SemaDeclCXX.cpp:0:0
#16 0x0000000005e04448 clang::RecursiveASTVisitor<clang::Sema::DiagnoseImmediateEscalatingReason(clang::FunctionDecl*)::ImmediateEscalatingExpressionsVisitor>::TraverseStmt(clang::Stmt*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*>>>>*) (.part.0) SemaDeclCXX.cpp:0:0
#17 0x0000000005e1b27d clang::RecursiveASTVisitor<clang::Sema::DiagnoseImmediateEscalatingReason(clang::FunctionDecl*)::ImmediateEscalatingExpressionsVisitor>::TraverseFunctionHelper(clang::FunctionDecl*) SemaDeclCXX.cpp:0:0
#18 0x0000000005dfe971 clang::RecursiveASTVisitor<clang::Sema::DiagnoseImmediateEscalatingReason(clang::FunctionDecl*)::ImmediateEscalatingExpressionsVisitor>::TraverseDecl(clang::Decl*) SemaDeclCXX.cpp:0:0
#19 0x0000000005dff695 clang::Sema::DiagnoseImmediateEscalatingReason(clang::FunctionDecl*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5dff695)
#20 0x0000000005ed3072 EvaluateAndDiagnoseImmediateInvocation(clang::Sema&, llvm::PointerIntPair<clang::ConstantExpr*, 1u, unsigned int, llvm::PointerLikeTypeTraits<clang::ConstantExpr*>, llvm::PointerIntPairInfo<clang::ConstantExpr*, 1u, llvm::PointerLikeTypeTraits<clang::ConstantExpr*>>>) SemaExpr.cpp:0:0
#21 0x0000000005f3528e clang::Sema::PopExpressionEvaluationContext() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5f3528e)
#22 0x0000000005d05a38 clang::Sema::ActOnFinishFunctionBody(clang::Decl*, clang::Stmt*, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5d05a38)
#23 0x0000000005aa18ef clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5aa18ef)
#24 0x00000000059bd158 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x59bd158)
#25 0x00000000059f0939 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x59f0939)
#26 0x00000000059b7a79 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x59b7a79)
#27 0x00000000059b88af clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.0) Parser.cpp:0:0
#28 0x00000000059c0102 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x59c0102)
#29 0x00000000059c1507 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x59c1507)
#30 0x00000000059b0eda clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x59b0eda)
#31 0x00000000045b38dd clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x45b38dd)
#32 0x0000000003e5f171 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3e5f171)
#33 0x0000000003ddedeb clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3ddedeb)
#34 0x0000000003f3d5b3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3f3d5b3)
#35 0x0000000000be7a15 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xbe7a15)
#36 0x0000000000be066d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#37 0x0000000003c30409 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
#38 0x0000000003314a23 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3314a23)
#39 0x0000000003c30629 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
#40 0x0000000003bf8937 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3bf8937)
#41 0x0000000003bf92ed 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+++0x3bf92ed)
#42 0x0000000003c0305c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3c0305c)
#43 0x0000000000be5001 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xbe5001)
#44 0x0000000000ae2cf1 main (/opt/compiler-explorer/clang-trunk/bin/clang+++0xae2cf1)
#45 0x00007f9ab4cf4083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#46 0x0000000000bdfe6e _start (/opt/compiler-explorer/clang-trunk/bin/clang+++0xbdfe6e)
clang++: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Compiler returned: 139
Related commits: 4676885 and 8698262 which implement P2564R3.