<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/87861>87861</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Clang-18 CRASHING on VALID recursive lambda code
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          nyyakko
      </td>
    </tr>
</table>

<pre>
    System:
`Windows 10 Pro 21H2`

Clang++:
```
PS C:\Users\Wellington> clang++ --version
clang version 18.1.3
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
```

Snippet:
```cpp
int main()
{
 std::string string {};

    for (auto index = 0zu; index < string.size(); index += 1)
    {
        if (string.at(index) == '<')
        {
            [&] (this auto self) -> void {
 index += 1;
                while (string.at(index) != '>')
 {
                    if (string.at(index) == '<')
 self();
                    else
                    {
 index += 1;
                    }
 }
                index += 1;
            }();
        }
 }
}
```

Backtrace (from compiler-explorer because the pre-compiled binary without debug info which doesn't give any meaningful info, see replies):
```
<source>:13:24: error: cannot compile this l-value expression yet
   13 |                 while (string.at(index) != '>')
      |                        ^~~~~~~~~
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-trunk/bin/clang++ -gdwarf-4 -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++23 <source>
1.      <eof> parser at end of file
2.      Per-file LLVM IR generation
3.      <source>:11:13: Generating code for declaration 'main()::(anonymous class)::operator()'
 #0 0x00000000036ac218 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x36ac218)
 #1 0x00000000036aa364 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x36aa364)
 #2 0x00000000035f2e98 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f8bb7442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x0000000003d11827 arrangeFreeFunctionLikeCall(clang::CodeGen::CodeGenTypes&, clang::CodeGen::CodeGenModule&, clang::CodeGen::CallArgList const&, clang::FunctionType const*, unsigned int, bool) CGCall.cpp:0:0
 #5 0x0000000003dac869 clang::CodeGen::CodeGenFunction::EmitCall(clang::QualType, clang::CodeGen::CGCallee const&, clang::CallExpr const*, clang::CodeGen::ReturnValueSlot, llvm::Value*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3dac869)
 #6 0x0000000003dae1b7 clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, clang::CodeGen::ReturnValueSlot) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3dae1b7)
 #7 0x0000000003df6fea (anonymous namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr const*) CGExprScalar.cpp:0:0
 #8 0x0000000003ded321 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
 #9 0x0000000003dfb888 (anonymous namespace)::ScalarExprEmitter::EmitBinOps(clang::BinaryOperator const*, clang::QualType) CGExprScalar.cpp:0:0
#10 0x0000000003dfbc9d (anonymous namespace)::ScalarExprEmitter::EmitCompare(clang::BinaryOperator const*, llvm::CmpInst::Predicate, llvm::CmpInst::Predicate, llvm::CmpInst::Predicate, bool) CGExprScalar.cpp:0:0
#11 0x0000000003deea0c clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#12 0x0000000003df3072 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3df3072)
#13 0x0000000003d91864 clang::CodeGen::CodeGenFunction::EvaluateExprAsBool(clang::Expr const*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3d91864)
#14 0x00000000039bb310 clang::CodeGen::CodeGenFunction::EmitWhileStmt(clang::WhileStmt const&, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x39bb310)
#15 0x00000000039b6eab clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x39b6eab)
#16 0x00000000039bc959 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x39bc959)
#17 0x0000000003a1b9d3 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3a1b9d3)
#18 0x0000000003a27c25 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3a27c25)
#19 0x0000000003a7f2db clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3a7f2db)
#20 0x0000000003a7afe3 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3a7afe3)
#21 0x0000000003a857c1 clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3a857c1)
#22 0x0000000003a87c63 clang::CodeGen::CodeGenModule::Release() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3a87c63)
#23 0x0000000003f1029e (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) ModuleBuilder.cpp:0:0
#24 0x0000000003f0efac clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3f0efac)
#25 0x0000000005db9b4c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5db9b4c)
#26 0x0000000003f0e665 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3f0e665)
#27 0x00000000041a3621 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x41a3621)
#28 0x00000000041299ab clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x41299ab)
#29 0x0000000004286f93 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4286f93)
#30 0x0000000000c4ce9c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xc4ce9c)
#31 0x0000000000c46e4d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#32 0x0000000003f57529 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
#33 0x00000000035f32c3 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x35f32c3)
#34 0x0000000003f57749 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
#35 0x0000000003f1dcb7 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3f1dcb7)
#36 0x0000000003f1e66d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3f1e66d)
#37 0x0000000003f2848c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3f2848c)
#38 0x0000000000c4a301 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xc4a301)
#39 0x0000000000b2e3e4 main (/opt/compiler-explorer/clang-trunk/bin/clang+++0xb2e3e4)
#40 0x00007f8bb7429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#41 0x00007f8bb7429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#42 0x0000000000c469ae _start (/opt/compiler-explorer/clang-trunk/bin/clang+++0xc469ae)
clang++: 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/eJzkWltz2ziT_TX0C4oqEqQk6sEPEmVnMpXZyUaZ5NEFgk0JaxBgAaAtzcP-9i2A1AW0ZMeJ9rvUp0psGZfGOQfN7iZBojVbC4DbYLwIxssb0pqNVLdityOPj_KmkOXudrXTBuogmQfRMojmwST6zkQpnzWKI_RZSYTj33Awifpu9zPnRKwDvLD_Tib2_9yfn1cot33j_C8NSgfj_DtwzsTaSBEkd4geTaAwfAKlmRTdVNeF-iYUZ6N4lHQ9X4lagwmSOdpmk4dJGjY0fO7QhrV-ov2ojQJSolqWwO3YRmq27bo-Cm0I51AumbJdPcTPSq4VqdE942Chfvr07Y9gnBdMnOXW_VwJ1jQOzWAQbZquhQmDasJEgLMAz_pR00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