C++20 lambdas in unevaluated context: crash on valid code · Issue #50376 · llvm/llvm-project (original) (raw)

Bugzilla Link 51032
Version trunk
OS Linux
CC @AaronBallman,@zygoloid

Extended Description

clang (trunk) crashes on the following valid c++20 program:

///////////////////////////////////////////////////////////////////////////////
template <typename T, typename Fn>
struct foo_t {
foo_t(T ptr) {}
};

template
using alias = foo_t<T, decltype( { return 0; })>;

template
auto fun(T const& t) -> alias {
return alias{t};
}

int main() {
int i;
auto const error = fun(i);
}
///////////////////////////////////////////////////////////////////////////////

PLEASE submit a bug report to https://bugs.llvm.org/ 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

  1. parser at end of file
  2. :14:5: LLVM IR generation of declaration 'main'
  3. :14:5: Generating code for declaration 'main'

#​0 0x000055bedd4185cf PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
#​1 0x000055bedd4164c0 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x33664c0)
#​2 0x000055bedd36abe8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#​3 0x00007fb1c17453c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
#​4 0x000055bedfc0547c clang::ASTContext::getTypeInfoImpl(clang::Type const*) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5b5547c)
#​5 0x000055bedfbf886d clang::ASTContext::getTypeInfo(clang::Type const*) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5b4886d)
#​6 0x000055bedfc0426b clang::ASTContext::getPreferredTypeAlign(clang::Type const*) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5b5426b)
#​7 0x000055bedfc066bb clang::ASTContext::getDeclAlign(clang::Decl const*, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5b566bb)
#​8 0x000055bedd9c6505 clang::CodeGen::CodeGenFunction::EmitAutoVarAlloca(clang::VarDecl const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3916505)
#​9 0x000055bedd9c727a clang::CodeGen::CodeGenFunction::EmitVarDecl(clang::VarDecl const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x391727a)
#​10 0x000055bedd9c757d clang::CodeGen::CodeGenFunction::EmitDecl(clang::Decl const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x391757d)
#​11 0x000055bedd73f327 clang::CodeGen::CodeGenFunction::EmitDeclStmt(clang::DeclStmt const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x368f327)
#​12 0x000055bedd74eaf5 clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x369eaf5)
#​13 0x000055bedd7493e2 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x36993e2)
#​14 0x000055bedd74e60c clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x369e60c)
#​15 0x000055bedd79b101 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x36eb101)
#​16 0x000055bedd7a3a17 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x36f3a17)
#​17 0x000055bedd7e8ffe clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3738ffe)
#​18 0x000055bedd7e5e25 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3735e25)
#​19 0x000055bedd7e652b clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x373652b)
#​20 0x000055bedd7ec101 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.5273) CodeGenModule.cpp:0:0
#​21 0x000055bede34be51 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#​22 0x000055bede33fc42 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x428fc42)
#​23 0x000055bedf19f1c4 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x50ef1c4)
#​24 0x000055bede349d62 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4299d62)
#​25 0x000055beddcfbe61 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3c4be61)
#​26 0x000055beddc99bc2 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3be9bc2)
#​27 0x000055bedddc8343 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3d18343)
#​28 0x000055bedb21f00c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x116f00c)
#​29 0x000055bedb21b19d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#​30 0x000055beddb486c5 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optionalllvm::StringRef >, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool) const::'lambda'()>(long) Job.cpp:0:0
#​31 0x000055bedd36b1d3 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x32bb1d3)
#​32 0x000055beddb4a59e clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optionalllvm::StringRef >, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3a9a59e)
#​33 0x000055beddb2075a clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3a7075a)
#​34 0x000055beddb212af 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+++0x3a712af)
#​35 0x000055beddb2a255 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3a7a255)
#​36 0x000055bedb133993 main (/opt/compiler-explorer/clang-trunk/bin/clang+++0x1083993)
#​37 0x00007fb1c11f50b3 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b3)
#​38 0x000055bedb21ad1a _start (/opt/compiler-explorer/clang-trunk/bin/clang+++0x116ad1a)
clang-13: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Compiler returned: 139

This was found while reporting a gcc bug (101315) and comparing gcc's output to clang's. See this link on godbolt: https://godbolt.org/z/5fcK1az5M