<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64961>64961</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang crash on short snippet with a static consteval function
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
nitnelave
</td>
</tr>
</table>
<pre>
Shortest reproducible example and environment: https://godbolt.org/z/Ys3fnjzKn
Reproduced here for posterity:
```c++
struct Base {
// Needs at least 3 fields
double a = 0.;
double b = 0.;
double c = 0.;
// Works with constexpr
static consteval Base zero() {
return Base{0., 0., 0.};
}
};
struct Derived: public Base {
static consteval Derived zero() {
return {Base::zero()};
}
};
/*
// Works
Base get_base() {
return Base::zero();
}
*/
// Crashes
Derived get() {
return Derived::zero();
}
```
Compiled with clang 16.0.0 or 16.0.5, with `-std=c++20`, we get:
```
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-16.0.0/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-12.2.0 -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 <source>
1. <eof> parser at end of file
2. Code generation
3. Running pass 'Function Pass Manager' on module '<source>'.
4. Running pass 'X86 DAG->DAG Instruction Selection' on function '@_Z3getv'
#0 0x0000559507e198df llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x3ba18df)
#1 0x0000559507e1790c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x3b9f90c)
#2 0x0000559507d6a518 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007f9bb888d420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#4 0x0000559506c36cb3 (anonymous namespace)::X86FastISel::X86SelectAddress(llvm::Value const*, llvm::X86AddressMode&) X86FastISel.cpp:0:0
#5 0x0000559506c3c7aa (anonymous namespace)::X86FastISel::fastSelectInstruction(llvm::Instruction const*) X86FastISel.cpp:0:0
#6 0x0000559508ebd91a llvm::FastISel::selectInstruction(llvm::Instruction const*) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x4c4591a)
#7 0x0000559508fbc547 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x4d44547)
#8 0x0000559508fbe27f llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (.part.0) SelectionDAGISel.cpp:0:0
#9 0x0000559506a1aa15 (anonymous namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) X86ISelDAGToDAG.cpp:0:0
#10 0x0000559507169cf0 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#11 0x0000559507682800 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x340a800)
#12 0x0000559507682979 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x340a979)
#13 0x0000559507683560 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x340b560)
#14 0x00005595082011da clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x3f891da)
#15 0x000055950910a238 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x4e92238)
#16 0x000055950a32ed5d clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x60b6d5d)
#17 0x0000559509109865 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x4e91865)
#18 0x00005595089e5671 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x476d671)
#19 0x0000559508969993 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x46f1993)
#20 0x0000559508ac9b3b clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x4851b3b)
#21 0x00005595055f241c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x137a41c)
#22 0x00005595055edbdc ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#23 0x00005595087cace9 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
#24 0x0000559507d6a977 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x3af2977)
#25 0x00005595087caf1c 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
#26 0x00005595087933fc clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x451b3fc)
#27 0x0000559508793ded clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x451bded)
#28 0x000055950879e23c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x452623c)
#29 0x00005595055f0523 clang_main(int, char**) (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x1378523)
#30 0x00007f9bb833b083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#31 0x00005595055e9d1e _start (/opt/compiler-explorer/clang-16.0.0/bin/clang+++0x1371d1e)
clang-16: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Compiler returned: 139
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWl1z27gV_TX0C4YaEuDngx9kycrudtNkYneb9kUDApcSNxDAAqAj76_vgKQkQpadpNX2pTtemwIugXMPzv0QGWpMs5EAt0F6F6TLG9rZrdK3srESBH2Cm0rx59uHrdIWjEUaWq14x5pKAII93bUCEJUcgXxqtJI7kDYgc7S1tjUBmQd4FeDVRvFKCTtTehPg1R8BXv3DkFr-_sdfZBAtg2g-_P40Lg4cbUEDqpVGrTIWdGOf3WIT2yCLhh8W4Dv3048aqztm0R01gIJ8HEQIoQEH-isAN4haJIAaiwiqGxDcnOy46pxnFAVkiaJZQO5ezFVvzLEXc-PGf1f6i0FfG7tFTEljYd_q093GUtuwceaJisGBP0CrABcBLie-aLCdlr1BkN9FswAv0PF3vvRAuc8DWZMJj6gl6OYJuDuxtqtEwy5Q9wLceNNlfON_I8wgv-uRknlA5if7HwDa8ze9HrkcRnq0G7Dryu3yFlfnCI67HLfG_frnW6_QQlOzhXHDg-8bsK9td-L0WzseJDzddKF2bSOAj1oRVG5QnM2iWYSUHq5Sd9r9dJBFobE8IMsxCnC_nJvuaXktZoaPD5ayL4h3u_ZoF82CqPyo1UbTHaJ607l4dnHsdKxaG-AVGwDqEPatUBq0G3MwwwFmgFdVIw-DAywUbvhXquswQeEGhcqtRtvWrdnZtrMzg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