<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/110301>110301</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang++] Frontend Crash in clang::Decl::castFromDeclContext
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
yype
</td>
</tr>
</table>
<pre>
Hello there, clang++ crashes on the following test case:
```cpp
a() { struct{[({ struct { b =
```
Tested version(s): 19.1.0, trunk.
Example: https://godbolt.org/z/nnj3sYKbP
Stack dump:
```
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-19.1.0/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-14.2.0 -fcolor-diagnostics -fno-crash-diagnostics -emit-llvm -O3 <source>
1. <eof> parser at end of file
2. <source>:1:5: parsing function body 'a'
#0 0x00000000036fdb08 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x36fdb08)
#1 0x00000000036fbc74 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x36fbc74)
#2 0x0000000003647be8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007a7aeb842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x0000000007196d90 clang::Decl::castFromDeclContext(clang::DeclContext const*) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x7196d90)
#5 0x00000000060a6b28 clang::Sema::checkTypeSupport(clang::QualType, clang::SourceLocation, clang::ValueDecl*) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x60a6b28)
#6 0x00000000062bae04 clang::Sema::ActOnFinishFunctionBody(clang::Decl*, clang::Stmt*, bool) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x62bae04)
#7 0x0000000006028c0f clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x6028c0f)
#8 0x0000000005f24740 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x5f24740)
#9 0x0000000005f6d07e clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x5f6d07e)
#10 0x0000000005f1e817 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x5f1e817)
#11 0x0000000005f1f703 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x5f1f703)
#12 0x0000000005f27cd2 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x5f27cd2)
#13 0x0000000005f29ac8 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x5f29ac8)
#14 0x0000000005f2a100 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x5f2a100)
#15 0x0000000005f18742 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x5f18742)
#16 0x0000000003fce825 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3fce825)
#17 0x0000000004274201 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x4274201)
#18 0x00000000041f699b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x41f699b)
#19 0x000000000435a843 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x435a843)
#20 0x0000000000c874dc cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0xc874dc)
#21 0x0000000000c8146d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#22 0x0000000004017309 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
#23 0x0000000003648013 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3648013)
#24 0x0000000004017529 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
#25 0x0000000003fdd947 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3fdd947)
#26 0x0000000003fde2fd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3fde2fd)
#27 0x0000000003fe7d4c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3fe7d4c)
#28 0x0000000000c847f1 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0xc847f1)
#29 0x0000000000b5c2d4 main (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0xb5c2d4)
#30 0x00007a7aeb829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#31 0x00007a7aeb829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#32 0x0000000000c80f0e _start (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0xc80f0e)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWV1v2zgW_TXMCyGDomRJfvCD49Qzme2i3ToYYJ8MiqIcTilSS1Kps79-QUpORCV2W6xmgMUWbaPw85xzL--9oogx_CgZW4PlLVje3ZDOPiq9fn5u2U2pquf1r0wIBe0j0wzgLaSCyCPAtwDfQqqJeWQGKun6Ya2EUN-4PELLjIWUGAaSDUB3AJ3_z1D_l7Zt30IALgBeQZDfQmN1Ry3Ibx0UXLw2-d4SguRussx47QdmLKvgE9OGKwlwYQBegWQD49UiXiCH3epOfl2MJ304kaYVDiZ8tLY1Di_eAbw7qqpUwi6UPgK8-zfAOyn_SMw__1Z-Hs_fW0K_wqpr2ktML45DC4BWn7U6atJAoo9dw6R1ACDAO9VagHdUNS0XTEfs1AqlmXZtTv_ozGlXcnluHIwSHatvRNdRCqMjjJRbjbStW7OzbWcXBkaNEE8NjKJTkUXENJF5lpacQHLHpWUCRrVU0RPTpTLM9cNoD6PoSGlklRL0kXDpTHENpRscpwu8QDCqqRJKRxUnR6mM5dT0O3jvCZtZw23Ug_uUQJBsjeo0ZSD50GsWO81AsmWqBskH2BJtmIbEQiYrqG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