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

    <tr>
        <th>Summary</th>
        <td>
            [Clang] Crash when taking the address of a capture in a lambda with an explicit object parameter in overload pattern
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:codegen,
            crash-on-valid
      </td>
    </tr>

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

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

<pre>
    Just documenting this here in case anyone else runs into this; from what I can tell, #84473 already fixes this. I haven’t really looked into this case in particular, but presumably, it’s broken because we currently erroneously treat by-reference captures as dependent in deducing-`this` lambdas even though they shouldn’t be.

This asserts in codegen (https://godbolt.org/z/1czjnznMK):
```C++
template <typename... Ts>
struct Overloaded : Ts... {
    using Ts::operator()...;
};

template <typename... Ts>
Overloaded(Ts...) -> Overloaded<Ts...>;

void f() {
    int x;
    Overloaded o {
        [&](this auto& self) {
            (void) &x;
        }
    };
    o();
}
```

Assertion:
```
clang++: /root/llvm-project/clang/lib/CodeGen/CGValue.h:277: 
void clang::CodeGen::LValue::initializeSimpleLValue(clang::CodeGen::Address, clang::QualType, clang::CodeGen::LValueBaseInfo, clang::CodeGen::TBAAAccessInfo, clang::ASTContext&): 
Assertion `Addr.getBasePointer()->getType()->isPointerTy()' failed.
```

Stack trace:
```
0.      Program arguments: /opt/compiler-explorer/clang-assertions-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++2c <source>
1.      <eof> parser at end of file
2.      Per-file LLVM IR generation
3.      <source>:12:9: Generating code for declaration 'f()::(anonymous class)::operator()'
 #0 0x0000000003928918 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3928918)
 #1 0x00000000039265fc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x39265fc)
 #2 0x000000000386cba8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f2d0a042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f2d0a0969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007f2d0a042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007f2d0a0287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007f2d0a02871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007f2d0a039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x0000000003c3e46c clang::CodeGen::LValue::MakeAddr(clang::CodeGen::Address, clang::QualType, clang::ASTContext&, clang::CodeGen::LValueBaseInfo, clang::CodeGen::TBAAAccessInfo) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3c3e46c)
#10 0x000000000404970f clang::CodeGen::CodeGenFunction::EmitLValueForField(clang::CodeGen::LValue, clang::FieldDecl const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x404970f)
#11 0x000000000404afdd clang::CodeGen::CodeGenFunction::EmitLValueForLambdaField(clang::FieldDecl const*, llvm::Value*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x404afdd)
#12 0x0000000004057af5 clang::CodeGen::CodeGenFunction::EmitDeclRefLValue(clang::DeclRefExpr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4057af5)
#13 0x00000000040549d2 clang::CodeGen::CodeGenFunction::EmitLValueHelper(clang::Expr const*, clang::CodeGen::KnownNonNull_t) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x40549d2)
#14 0x0000000004054d11 clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*, clang::CodeGen::KnownNonNull_t) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4054d11)
#15 0x00000000040a94ff clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#16 0x00000000040ae26c clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x40ae26c)
#17 0x000000000403f14e clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x403f14e)
#18 0x0000000004060dc1 clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4060dc1)
#19 0x00000000040b0437 (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) CGExprScalar.cpp:0:0
#20 0x00000000040a7a53 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#21 0x00000000040ae26c clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x40ae26c)
#22 0x000000000403f14e clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x403f14e)
#23 0x0000000004060dc1 clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4060dc1)
#24 0x0000000003c4f155 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3c4f155)
#25 0x0000000003c559ec clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3c559ec)
#26 0x0000000003cb79b1 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3cb79b1)
#27 0x0000000003ccb2ca clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ccb2ca)
#28 0x0000000003d2a8d2 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3d2a8d2)
#29 0x0000000003d25195 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3d25195)
#30 0x0000000003d3123d clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3d3123d)
#31 0x0000000003d33ae3 clang::CodeGen::CodeGenModule::Release() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3d33ae3)
#32 0x00000000041d538e (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) ModuleBuilder.cpp:0:0
#33 0x00000000041d3ea5 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x41d3ea5)
#34 0x00000000061d59bc clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x61d59bc)
#35 0x00000000041d3768 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x41d3768)
#36 0x0000000004453779 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4453779)
#37 0x00000000043dd09e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43dd09e)
#38 0x00000000045364ee clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x45364ee)
#39 0x0000000000c3e6ec cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc3e6ec)
#40 0x0000000000c3797a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#41 0x00000000042166e9 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
#42 0x000000000386d054 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x386d054)
#43 0x0000000004216cdf 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
#44 0x00000000041dd075 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x41dd075)
#45 0x00000000041ddadd 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+++0x41ddadd)
#46 0x00000000041e5845 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x41e5845)
#47 0x0000000000c3bb85 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc3bb85)
#48 0x0000000000b1ed54 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xb1ed54)
#49 0x00007f2d0a029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#50 0x00007f2d0a029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#51 0x0000000000c3746e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc3746e)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkW19z4yqy_zTkhbJLQrL-POTBcZLZnJ3ZnTvJnfvoQtCydYJBBSgTz6e_BZJjoziZZCre2jpnKueUjZrm9-tumgZhakyzkgDnaHaBCLlttKYNB0QIml2e0c6ulT7ftZ5Vim_P_-iMxVyxbgPSNnKF7boxeA0acCMxowYwlVslAYMwgHUnDW6kVV4OJRe41mqDf6ypxTeYUYktCIHIAiOSFGmaJ5gKDZRvcd08gvHdpvgGr-kDSHRFUBGhsrRYAxVii4VS98D3I_QIGolbqm3DOkG1U151FrcaTLehldi6lsY-KTO40uoeJK6A0c4A_gGYdVqDtGKLQWslQXVGbLHVQC2uthMNNWiQDDCjre00GEwN5tCC5CCtA8CBd6yRqwnKIs89i7Cgm4pTg-EBJLZr1a3W2K5hi81adYIf8qtgiqJLFM37_985btQY0NZ4QysOK5AYkWJtbWtQMkfkGpHrleKVEnaq9AqR65-IXMfs55_yp_zyT0RKJ9ZrzaL-b4HIhfvzrRY2raAWMEoWdtuCpBuYTqf4zqDkqhcxVnfM4n8_gBaKcuAYJXN8Z5wYygc9GGPcGRcddx5ZMlctaGqVRqRApJxOpygZZFF-uf_8VhT74REp_OCIlHiCkqsDZChZ9I-Sq9EID6rhuO6xhKgbafHjk7RrOWCqQln3z0-cDM0uESl8_NHOKkQybEDUz7Q_9S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