<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/76401>76401</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang front-end "unhandled decl kind" assertion failure on invalid consteval calls
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ts826848
</td>
</tr>
</table>
<pre>
I have two related programs that cause a Clang frontend segfault in release mode. The programs trigger an "unhandled decl kind" assertion in Godbolt's Clang-with-assertions build.
[The first program](https://godbolt.org/z/GxMKW4avx) contains call to a consteval constructor with an immediately-invoked lambda that has a non-constant expression capture as the argument:
```cpp
#include <initializer_list>
struct vector {
~vector() {}
};
struct set {
vector vals;
consteval set(std::initializer_list<int> init_vals) {}
};
auto f(int i) {
set{};
set{[i]() -> int {}()};
}
```
[The second](https://godbolt.org/z/7foParfMP) invokes a `consteval` constructor with no definition:
```cpp
#include <initializer_list>
struct vector {
~vector();
};
struct set {
vector vals;
consteval set(std::initializer_list<int>);
};
auto f() -> int {
set{};
set{};
}
```
The following changes appear to make the programs compile:
- Removing the duplicate `set` temporary creation
- Removing the `vector` destructor
- Removing the `vals` member from `set`
- Removing the lambda from the first example program
- Adding a constructor definition to the second program
Here's the stack trace from Godbolt's Clang 17.0.1-with-assertions build for the first example:
```
unhandled decl kind
UNREACHABLE executed at /root/llvm-project/clang/lib/Sema/SemaExpr.cpp:18259!
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-17.0.1/bin/clang++ -gdwarf-4 -g -o /app/output.s -S --gcc-toolchain=/opt/compiler-explorer/gcc-13.2.0 -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 <source>
1. <eof> parser at end of file
2. <source>:9:15: parsing function body 'f'
#0 0x00000000036e7558 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x36e7558)
#1 0x00000000036e53dc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x36e53dc)
#2 0x0000000003632918 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007f02baa42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007f02baa969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x00007f02baa42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x00007f02baa287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x000000000363dbca (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x363dbca)
#8 0x000000000631a5c8 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
#9 0x000000000635b34e clang::Sema::PopExpressionEvaluationContext() (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x635b34e)
#10 0x000000000614fa40 clang::Sema::ActOnFinishFunctionBody(clang::Decl*, clang::Stmt*, bool) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x614fa40)
#11 0x0000000005ecd3ad clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5ecd3ad)
#12 0x0000000005dfbe81 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5dfbe81)
#13 0x0000000005e22648 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5e22648)
#14 0x0000000005defc4a clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5defc4a)
#15 0x0000000005df04df clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.0) Parser.cpp:0:0
#16 0x0000000005df6b51 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5df6b51)
#17 0x0000000005df7452 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5df7452)
#18 0x0000000005deb76a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5deb76a)
#19 0x0000000004939258 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x4939258)
#20 0x00000000041a1c09 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x41a1c09)
#21 0x00000000041278ce clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x41278ce)
#22 0x0000000004281de6 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x4281de6)
#23 0x0000000000bc67eb cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0xbc67eb)
#24 0x0000000000bbefaa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#25 0x0000000003f83419 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
#26 0x0000000003632dc4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3632dc4)
#27 0x0000000003f83a0f 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
#28 0x0000000003f4b275 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3f4b275)
#29 0x0000000003f4bcdd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3f4bcdd)
#30 0x0000000003f5385d clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3f5385d)
#31 0x0000000000bc4a87 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0xbc4a87)
#32 0x0000000000abef61 main (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0xabef61)
#33 0x00007f02baa29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#34 0x00007f02baa29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#35 0x0000000000bbea8e _start (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0xbbea8e)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
The stack trace for the second program looks pretty similar at a first glance.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWl9346oR_zTKC8c-Evrrhzw4TrI3t7ndnE3aPvogQDYNEiogr3Mf-tl7ANkWsp3NtvG-dE_WcSRm5je_GYZBAinFVg2l10F6E6S3V6jTayGvtSpgViTFVSnI2_UDWKMNBfq7AJJypCkBrRQriWoF9BppgFGnKEBgwVGzApUUjaYNAYquKtRxDVhjBClSFNSC0Cl4WdOBCslWKyoBakAAYdesUUM4JYBQzMEra0gAIUBKUamZaIyyL4KUgusA5srZnHxnej3Zj1Gg7Bgn0yC8DcJ5_5neGKsVk0rvbAfpbQCLtdatCuJ5AO8DeL9yuqdCrgJ4_2cA779s__jLPxK02QZwBrBoNGKNAhhxDrQAyFxSmm4Qd99kh7WQwCAyLrG6poQhTfnbhDUb8UoJ4KguCXLcrZECCDSimVhp1GhAt62kShlnMWp1JylAhmkKkFx1NW20Qeu8ykL3g9u2vwJj1mDeEQqCeMEaphni7E8ql5wpHcR3bpjDCTbUgg3yG3cZgH-7SwEsjLvmRn7ba85vg_jGE1dUD2V7bRvE1X4kGPCjqA5goTQx-OP5MbgFM77dAXNnadW8gwF1WoAqgAVrNGC7kb1RY8rJxeNr6Q1zgTciE2dO76zYq0Oxg-kd1SeySlEsGvKxdMor8YRk9ceTMe8ywmSAieGOqCALj3OpEYDQynImmiCeg1-SAR4Pvyb656zu430Ut_MxP770fjxtiRCci--sWQG8Rs3KRKdtKZJmttfoldqZuK9eWNQt4_QwI-3nBHyjtdgYJWY06VrOMNLUhNlgykKgad0KieQbwJIiG9RTokEW9vHIQkDoLifOjjXsZyGoaV1SaWpxfbB5UqgvRnak3ldIukV1y_d-7iTnhBg55KXnIS0NRXo_H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