<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/117385>117385</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Assertion failure with `if consteval` + `-Wconsumed`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
davidstone
</td>
</tr>
</table>
<pre>
The following valid translation unit:
```c++
void f() {
if consteval {
}
}
```
when compiled with `-std=c++23 -Wconsumed` causes clang to fail with
```console
clang++: /root/llvm-project/llvm/include/llvm/Support/Casting.h:662: decltype(auto) llvm::dyn_cast(From*) [with To = clang::ExprWithCleanups; From = const clang::Expr]: Assertion `detail::isPresent(Val) && "dyn_cast on a non-existent value"' failed.
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-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++23 -Wconsumed <source>
1. <eof> parser at end of file
2. <source>:1:10: parsing function body 'f'
#0 0x0000000003bfabd8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3bfabd8)
#1 0x0000000003bf88dc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3bf88dc)
#2 0x0000000003b45fc8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007e7b14e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007e7b14e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x00007e7b14e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x00007e7b14e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x00007e7b14e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x00007e7b14e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x00000000071bfed4 clang::consumed::ConsumedStmtVisitor::getInfo(clang::Expr const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71bfed4)
#10 0x00000000071c5327 clang::consumed::ConsumedAnalyzer::splitState(clang::CFGBlock const*, clang::consumed::ConsumedStmtVisitor const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71c5327)
#11 0x00000000071ca1be clang::consumed::ConsumedAnalyzer::run(clang::AnalysisDeclContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71ca1be)
#12 0x0000000007132088 clang::sema::AnalysisBasedWarnings::IssueWarnings(clang::sema::AnalysisBasedWarnings::Policy, clang::sema::FunctionScopeInfo*, clang::Decl const*, clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7132088)
#13 0x000000000669a286 clang::Sema::PopFunctionScopeInfo(clang::sema::AnalysisBasedWarnings::Policy const*, clang::Decl const*, clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x669a286)
#14 0x00000000068b72f0 clang::Sema::ActOnFinishFunctionBody(clang::Decl*, clang::Stmt*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x68b72f0)
#15 0x000000000661e68f clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x661e68f)
#16 0x0000000006531f03 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6531f03)
#17 0x00000000065666bd clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x65666bd)
#18 0x0000000006525c4e clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6525c4e)
#19 0x000000000652640e clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x652640e)
#20 0x000000000652dba3 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x652dba3)
#21 0x000000000652ea8d clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x652ea8d)
#22 0x000000000652ef30 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x652ef30)
#23 0x0000000006520f72 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6520f72)
#24 0x000000000457dcb8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x457dcb8)
#25 0x00000000048383a9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48383a9)
#26 0x00000000047b82be clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47b82be)
#27 0x000000000492333e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x492333e)
#28 0x0000000000caa161 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcaa161)
#29 0x0000000000ca1cea ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#30 0x00000000045c0eb9 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
#31 0x0000000003b46474 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3b46474)
#32 0x00000000045c14af 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
#33 0x000000000458779d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x458779d)
#34 0x000000000458888d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x458888d)
#35 0x000000000458fc45 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x458fc45)
#36 0x0000000000ca6f93 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xca6f93)
#37 0x0000000000b7da84 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xb7da84)
#38 0x00007e7b14e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#39 0x00007e7b14e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#40 0x0000000000ca179e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xca179e)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
See it live: https://godbolt.org/z/643oYTrqh
This was introduced by fe697efe @a-tarasyuk @AaronBallman
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWl1v47iS_TXMC6FAomRJfsiD47Rne9CLzraDGeyTQVElm9s0qSEpx5lfvyAlO6KTuDuDuC9w76AzkPlRPOewWCyJpMbwtQS4QZNbNLm7op3dKH1T0x2vjVUSripVP908bAA3Sgj1yOUa76jgNbaaSiOo5UriTnKL0hmK71B8-H8e9_8YIrfuny_dKV7jBpESkSlGxe2hx5Q3mClpLOyoCCpQcTc8Hx8OlsfDPW5AYqa2LRdQ40duNxjlcWRsjdK7AQJJcfSnG6XbQo3yGDPaGTCYCSrX2CrcUC5839eJKGmUgL7U9xmYpTOMyEIrZRFZCLHbRq1W_wfs8BORBZdMdDU8Fyy7tlXatZhTY7lcX29QOstz4qzVwIR9agGRknZWOa18t3SG0ln9JFeMGotIudBqi8jMazm59aQfFEbpXU-pb_9p3-o_ud3MBVDZtQalt9h17Ns5zU9bo8mdQzEzBrSfXpTHNVjKRd-Gm3sNBqSD8AcVfniSI5JjRMgBHlYSUyyVjGDPjQVpnd90gAhBpPBSQ33di3n_5dNs-QmbrtpyiymuujXW4PRxs7Kx1qGeIbJAZLHmdtNV18wxP4h5ojk3pgODyAJTWeNBemw3gJmmZoMryr5bTRkgMsethlYrBsZAjY3qdF_selJjFOPUQo11J7Fhmrd2gLy0lH3Hdbdtj34fX6N4eq_VWtMtpnrdbUFaM3iHah2ywUF1BPtWKA3alTnxI3oQ20RWd_I7IouKy0N172g4WtePVDdRhqM1j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