git: 8e0b0a282739 - stable/13 - Merge commit f5f3d5d6534f from llvm-project (by Qizhi Hu):

From: Dimitry Andric <dim_at_FreeBSD.org>
Date: Sat, 20 Apr 2024 10:34:43 UTC
The branch stable/13 has been updated by dim:

URL: https://cgit.FreeBSD.org/src/commit/?id=8e0b0a282739fadcc6cdec8bf1d8080c50f22bd0

commit 8e0b0a282739fadcc6cdec8bf1d8080c50f22bd0
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2024-03-21 20:50:26 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2024-04-19 21:24:48 +0000

    Merge commit f5f3d5d6534f from llvm-project (by Qizhi Hu):
    
      [Clang][Sema] Fix a crash in lambda instantiation (#85565)
    
      Fix https://github.com/llvm/llvm-project/issues/85343
      When build lambda expression in lambda instantiation, `ThisType` is
      required in `Sema::CheckCXXThisCapture` to build `this` capture. Set
      `this` type by import `Sema::CXXThisScopeRAII` and it will be used later
      in lambda expression transformation.
    
      Co-authored-by: huqizhi <836744285@qq.com>
    
    This fixes 'Assertion failed: (!isNull() && "Cannot retrieve a NULL type
    pointer"), function getCommonPtr" when building the x11-wm/wayfire port.
    
    PR:             276104
    MFC after:      1 month
    
    (cherry picked from commit 49a6e426df84eff1ae54905a02f66910a6a177d3)
---
 contrib/llvm-project/clang/lib/Sema/TreeTransform.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/contrib/llvm-project/clang/lib/Sema/TreeTransform.h b/contrib/llvm-project/clang/lib/Sema/TreeTransform.h
index e55e752b9cc3..2f012cade6b9 100644
--- a/contrib/llvm-project/clang/lib/Sema/TreeTransform.h
+++ b/contrib/llvm-project/clang/lib/Sema/TreeTransform.h
@@ -13516,6 +13516,16 @@ TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
 
     // Capturing 'this' is trivial.
     if (C->capturesThis()) {
+      // If this is a lambda that is part of a default member initialiser
+      // and which we're instantiating outside the class that 'this' is
+      // supposed to refer to, adjust the type of 'this' accordingly.
+      //
+      // Otherwise, leave the type of 'this' as-is.
+      Sema::CXXThisScopeRAII ThisScope(
+          getSema(),
+          dyn_cast_if_present<CXXRecordDecl>(
+              getSema().getFunctionLevelDeclContext()),
+          Qualifiers());
       getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
                                     /*BuildAndDiagnose*/ true, nullptr,
                                     C->getCaptureKind() == LCK_StarThis);