https://github.com/akash-manna-sky updated 
https://github.com/llvm/llvm-project/pull/243509

>From 43b09a81b7278ba9a39e2687c90e9268c8c9d143 Mon Sep 17 00:00:00 2001
From: Akash Manna <[email protected]>
Date: Thu, 12 Nov 2026 20:08:14 +0530
Subject: [PATCH 1/3] [Clang][CodeGen] Fix crash on a block capturing this in
 an aggregate's default member initializer

Fixes #229323

`computeBlockInfo` typed a block's captured `this` from `CurFuncDecl`, assuming 
the literal is emitted in a member function of that class. A default member 
initializer is emitted wherever the object is initialized, which for an 
aggregate can be a free function, so the `cast<CXXMethodDecl>` asserted. 
Closures nested in such an initializer have no `CurFuncDecl` at all and failed 
the same way even inside a constructor.

`CXXDefaultInitExprScope` now records the type of the `this` it substitutes, 
`CodeGenFunction::getCXXThisType()` resolves the current `this` from that 
override, the enclosing closure's capture, or the method, and 
`computeBlockInfo` and the block's debug info use it.

LLM tools were used for this contribution.
---
 clang/docs/ReleaseNotes.md                    |  1 +
 clang/lib/CodeGen/CGBlocks.cpp                |  7 +-
 clang/lib/CodeGen/CGBlocks.h                  |  3 +
 clang/lib/CodeGen/CGClass.cpp                 | 23 ++++++
 clang/lib/CodeGen/CGDebugInfo.cpp             | 13 +--
 clang/lib/CodeGen/CodeGenFunction.h           | 18 +++++
 clang/test/CodeGenCXX/blocks.cpp              | 79 +++++++++++++++++++
 .../DebugInfo/ObjCXX/block-capture-this.mm    | 21 +++--
 8 files changed, 146 insertions(+), 19 deletions(-)

diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 6d1dbbbb6eb77b..1a214744003569 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -795,6 +795,7 @@ documentation](CIR/index.md) for more information regarding 
ClangIR's status and
 - Fixed IEEE f128 complex mul/div using the IBM f128 libcalls on powerpc. 
(#GH216820)
 - Fixed an ICE that occurred when a structured binding pack is expanded 
outside the lambda where it was declared. (#GH214160)
 - Fixed a crash when a statement expression in the initializer of a 
new-expression starts with a loop or a label. (#GH175427)
+- Fixed a crash when a block in a default member initializer captures `this` 
and the class is aggregate-initialized outside of its member functions. 
(#GH229323)
 - Fixed a bug where a stray closing curley brace in an OpenMP/OpenACC pragma 
could cause pragma parsing issues when inside of a member function. (#GH214195)
 - Fixed a bug where preprocessor directives following comments were not 
correctly recognized when using -C. (#GH48361)
 - Fixed a crash when declaring a member template within a local class inside 
an OpenMP region. (#GH216052)
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index 26c34925b7a651..fdfd39c9dffb17 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -582,9 +582,10 @@ static void computeBlockInfo(CodeGenModule &CGM, 
CodeGenFunction *CGF,
 
   // First, 'this'.
   if (block->capturesCXXThis()) {
-    assert(CGF && isa_and_nonnull<CXXMethodDecl>(CGF->CurFuncDecl) &&
-           "Can't capture 'this' outside a method");
-    QualType thisType = cast<CXXMethodDecl>(CGF->CurFuncDecl)->getThisType();
+    assert(CGF && "Can't capture 'this' in a global block");
+    QualType thisType = CGF->getCXXThisType();
+    assert(!thisType.isNull() && "No 'this' to capture here");
+    info.CXXThisType = thisType;
 
     // Theoretically, this could be in a different address space, so
     // don't assume standard pointer size/align.
diff --git a/clang/lib/CodeGen/CGBlocks.h b/clang/lib/CodeGen/CGBlocks.h
index b2e850046ab9af..73240fe1f65318 100644
--- a/clang/lib/CodeGen/CGBlocks.h
+++ b/clang/lib/CodeGen/CGBlocks.h
@@ -281,6 +281,9 @@ class CGBlockInfo {
   CharUnits BlockAlign;
   CharUnits CXXThisOffset;
 
+  /// The type of the captured 'this', if there is one.
+  QualType CXXThisType;
+
   // Offset of the gap caused by block header having a smaller
   // alignment than the alignment of the block descriptor. This
   // is the gap offset before the first capturued field.
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index 2901233638ffee..42a1d001a12b82 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -146,6 +146,29 @@ Address CodeGenFunction::LoadCXXThisAddress() {
       false, nullptr, nullptr, KnownNonNull);
 }
 
+QualType CodeGenFunction::getCXXThisType() const {
+  if (!CXXThisTypeOverride.isNull())
+    return CXXThisTypeOverride;
+
+  // A lambda capturing '*this' by copy points 'this' at the copy.
+  if (LambdaThisCaptureField) {
+    QualType FieldTy = LambdaThisCaptureField->getType();
+    return FieldTy->isPointerType() ? FieldTy
+                                    : getContext().getPointerType(FieldTy);
+  }
+
+  if (BlockInfo && BlockInfo->getBlockDecl()->capturesCXXThis())
+    return BlockInfo->CXXThisType;
+  if (CapturedStmtInfo && CapturedStmtInfo->isCXXThisExprCaptured())
+    return CapturedStmtInfo->getThisFieldDecl()->getType();
+
+  if (const auto *MD = dyn_cast_if_present<CXXMethodDecl>(CurFuncDecl);
+      MD && MD->isImplicitObjectMemberFunction())
+    return MD->getThisType();
+
+  return QualType();
+}
+
 /// Emit the address of a field using a member data pointer.
 ///
 /// \param E Only used for emergency diagnostics
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 436a949891793c..8b228d0890e334 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -6026,17 +6026,8 @@ void 
CGDebugInfo::EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
 
     // If we have a null capture, this must be the C++ 'this' capture.
     if (!capture) {
-      QualType type;
-      if (auto *Method =
-              cast_or_null<CXXMethodDecl>(blockDecl->getNonClosureContext()))
-        type = Method->getThisType();
-      else if (auto *RDecl = dyn_cast<CXXRecordDecl>(blockDecl->getParent()))
-        type = CGM.getContext().getCanonicalTagType(RDecl);
-      else
-        llvm_unreachable("unexpected block declcontext");
-
-      fields.push_back(createFieldType("this", type, loc, AS_public,
-                                       offsetInBits, tunit, tunit));
+      fields.push_back(createFieldType("this", block.CXXThisType, loc,
+                                       AS_public, offsetInBits, tunit, tunit));
       continue;
     }
 
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index 4cc0a45067a017..d452391bc4d431 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -1899,19 +1899,25 @@ class CodeGenFunction : public CodeGenTypeCache {
     CXXDefaultInitExprScope(CodeGenFunction &CGF, const CXXDefaultInitExpr *E)
         : CGF(CGF), OldCXXThisValue(CGF.CXXThisValue),
           OldCXXThisAlignment(CGF.CXXThisAlignment),
+          OldCXXThisTypeOverride(CGF.CXXThisTypeOverride),
           SourceLocScope(E, CGF.CurSourceLocExprScope) {
       CGF.CXXThisValue = CGF.CXXDefaultInitExprThis.getBasePointer();
       CGF.CXXThisAlignment = CGF.CXXDefaultInitExprThis.getAlignment();
+      // [expr.prim.general]p4: 'this' is "pointer to X" in X's initializers.
+      CGF.CXXThisTypeOverride = CGF.getContext().getPointerType(
+          CGF.getContext().getCanonicalTagType(E->getField()->getParent()));
     }
     ~CXXDefaultInitExprScope() {
       CGF.CXXThisValue = OldCXXThisValue;
       CGF.CXXThisAlignment = OldCXXThisAlignment;
+      CGF.CXXThisTypeOverride = OldCXXThisTypeOverride;
     }
 
   public:
     CodeGenFunction &CGF;
     llvm::Value *OldCXXThisValue;
     CharUnits OldCXXThisAlignment;
+    QualType OldCXXThisTypeOverride;
     SourceLocExprScopeGuard SourceLocScope;
   };
 
@@ -1945,6 +1951,7 @@ class CodeGenFunction : public CodeGenTypeCache {
           OldCXXThisValue(CGF.CXXThisValue),
           OldCXXABIThisAlignment(CGF.CXXABIThisAlignment),
           OldCXXThisAlignment(CGF.CXXThisAlignment),
+          OldCXXThisTypeOverride(CGF.CXXThisTypeOverride),
           OldReturnValue(CGF.ReturnValue), OldFnRetTy(CGF.FnRetTy),
           OldCXXInheritedCtorInitExprArgs(
               std::move(CGF.CXXInheritedCtorInitExprArgs)) {
@@ -1956,6 +1963,7 @@ class CodeGenFunction : public CodeGenTypeCache {
       CGF.CXXThisValue = nullptr;
       CGF.CXXABIThisAlignment = CharUnits();
       CGF.CXXThisAlignment = CharUnits();
+      CGF.CXXThisTypeOverride = QualType();
       CGF.ReturnValue = Address::invalid();
       CGF.FnRetTy = QualType();
       CGF.CXXInheritedCtorInitExprArgs.clear();
@@ -1969,6 +1977,7 @@ class CodeGenFunction : public CodeGenTypeCache {
       CGF.CXXThisValue = OldCXXThisValue;
       CGF.CXXABIThisAlignment = OldCXXABIThisAlignment;
       CGF.CXXThisAlignment = OldCXXThisAlignment;
+      CGF.CXXThisTypeOverride = OldCXXThisTypeOverride;
       CGF.ReturnValue = OldReturnValue;
       CGF.FnRetTy = OldFnRetTy;
       CGF.CXXInheritedCtorInitExprArgs =
@@ -1985,6 +1994,7 @@ class CodeGenFunction : public CodeGenTypeCache {
     llvm::Value *OldCXXThisValue;
     CharUnits OldCXXABIThisAlignment;
     CharUnits OldCXXThisAlignment;
+    QualType OldCXXThisTypeOverride;
     Address OldReturnValue;
     QualType OldFnRetTy;
     CallArgList OldCXXInheritedCtorInitExprArgs;
@@ -2186,6 +2196,10 @@ class CodeGenFunction : public CodeGenTypeCache {
   /// this expression.
   Address CXXDefaultInitExprThis = Address::invalid();
 
+  /// The type of 'this' while evaluating a CXXDefaultInitExpr: a pointer to
+  /// the class being initialized, which need not be CurFuncDecl's class.
+  QualType CXXThisTypeOverride;
+
   /// The current array initialization index when evaluating an
   /// ArrayInitIndexExpr within an ArrayInitLoopExpr.
   llvm::Value *ArrayInitIndex = nullptr;
@@ -3263,6 +3277,10 @@ class CodeGenFunction : public CodeGenTypeCache {
   }
   Address LoadCXXThisAddress();
 
+  /// Return the type of the pointer LoadCXXThis() returns, or null if there is
+  /// no 'this' here.
+  QualType getCXXThisType() const;
+
   /// LoadCXXVTT - Load the VTT parameter to base constructors/destructors have
   /// virtual bases.
   // FIXME: Every place that calls LoadCXXVTT is something
diff --git a/clang/test/CodeGenCXX/blocks.cpp b/clang/test/CodeGenCXX/blocks.cpp
index d2da46b4ab48ff..5f35889f344504 100644
--- a/clang/test/CodeGenCXX/blocks.cpp
+++ b/clang/test/CodeGenCXX/blocks.cpp
@@ -274,6 +274,85 @@ namespace test10 {
   }
 }
 
+namespace test11 {
+  // A block in a default member initializer captures the object being
+  // initialized, wherever the initializer happens to be emitted.
+  struct A {
+    int x;
+    int func();
+    int (^callMember)() = ^{ return func(); };
+    int (^useField)() = ^{ return x; };
+  };
+  template <class T> struct TA {
+    int func();
+    int (^callMember)() = ^{ return func(); };
+  };
+  struct B {
+    int func();
+    int (^nested)() = ^{ return ^{ return func(); }(); };
+    int viaLambda = [this] { return ^{ return func(); }(); }();
+  };
+  struct Other {
+    int y;
+    void m();
+    static void s();
+  };
+
+  // CHECK-LABEL: define{{.*}} void @_ZN6test112f1Ev()
+  // CHECK:       [[T:%.*]] = alloca %"struct.test11::A",
+  // CHECK:       [[BLOCK:%.*]] = alloca [[BLOCK_T:<{.*}>]],
+  // CHECK:       store ptr @___ZN6test112f1Ev_block_invoke, ptr
+  // CHECK:       [[THIS_ADDR:%.*]] = getelementptr inbounds nuw [[BLOCK_T]], 
ptr [[BLOCK]], i32 0, i32 5
+  // CHECK-NEXT:  store ptr [[T]], ptr [[THIS_ADDR]],
+  // CHECK:       store ptr @___ZN6test112f1Ev_block_invoke_2, ptr
+  // CHECK:       store ptr [[T]], ptr
+  void f1() { A t{}; }
+
+  // CHECK-LABEL: define internal noundef i32 @___ZN6test112f1Ev_block_invoke(
+  // CHECK:       [[THIS:%.*]] = load ptr, ptr
+  // CHECK-NEXT:  call noundef i32 @_ZN6test111A4funcEv(ptr {{[^,]*}} [[THIS]])
+
+  // CHECK-LABEL: define internal noundef i32 
@___ZN6test112f1Ev_block_invoke_2(
+  // CHECK:       [[THIS:%.*]] = load ptr, ptr
+  // CHECK-NEXT:  [[X:%.*]] = getelementptr inbounds nuw %"struct.test11::A", 
ptr [[THIS]], i32 0, i32 0
+  // CHECK-NEXT:  load i32, ptr [[X]],
+
+  // Not the 'this' of the member function emitting the initializer.
+  // CHECK-LABEL: define{{.*}} void @_ZN6test115Other1mEv(ptr {{[^,]*}} %this)
+  // CHECK:       [[T:%.*]] = alloca %"struct.test11::A",
+  // CHECK:       [[BLOCK:%.*]] = alloca [[BLOCK_T]],
+  // CHECK:       [[THIS_ADDR:%.*]] = getelementptr inbounds nuw [[BLOCK_T]], 
ptr [[BLOCK]], i32 0, i32 5
+  // CHECK-NEXT:  store ptr [[T]], ptr [[THIS_ADDR]],
+  void Other::m() { A t{}; }
+
+  // CHECK-LABEL: define{{.*}} void @_ZN6test115Other1sEv()
+  // CHECK:       [[T:%.*]] = alloca %"struct.test11::A",
+  // CHECK:       store ptr [[T]], ptr
+  void Other::s() { A t{}; }
+
+  // CHECK-LABEL: define{{.*}} void @_ZN6test112f2Ev()
+  // CHECK:       [[T:%.*]] = alloca %"struct.test11::TA",
+  // CHECK:       store ptr [[T]], ptr
+  void f2() { TA<int> t{}; }
+
+  // CHECK-LABEL: define{{.*}} void @_ZN6test112f3Ev()
+  // CHECK:       [[T:%.*]] = alloca %"struct.test11::B",
+  // CHECK:       store ptr [[T]], ptr
+  void f3() { B t{}; }
+
+  // CHECK-LABEL: define internal noundef i32 @___ZN6test112f3Ev_block_invoke(
+  // CHECK:       [[THIS:%.*]] = load ptr, ptr
+  // CHECK:       store ptr [[THIS]], ptr
+
+  // CHECK-LABEL: define internal noundef i32 
@___ZN6test112f3Ev_block_invoke_2(
+  // CHECK:       [[THIS:%.*]] = load ptr, ptr
+  // CHECK-NEXT:  call noundef i32 @_ZN6test111B4funcEv(ptr {{[^,]*}} [[THIS]])
+
+  // CHECK-LABEL: define internal void @__cxx_global_var_init()
+  // CHECK:       store ptr @_ZN6test112gaE, ptr
+  A ga{};
+}
+
 // Copy/dispose helper functions and block descriptors of blocks that capture
 // objects that are non-external and non-trivial have internal linkage.
 
diff --git a/clang/test/DebugInfo/ObjCXX/block-capture-this.mm 
b/clang/test/DebugInfo/ObjCXX/block-capture-this.mm
index 9464222b543b58..eafa24d6502b17 100644
--- a/clang/test/DebugInfo/ObjCXX/block-capture-this.mm
+++ b/clang/test/DebugInfo/ObjCXX/block-capture-this.mm
@@ -3,6 +3,7 @@
 {
     int func() { return 1; }
     int (^block)() = ^{ return func(); };
+    int viaLambda = [this] { return ^{ return func(); }(); }();
 };
 
 int main(int argc, const char * argv[]) {
@@ -10,11 +11,21 @@ int main(int argc, const char * argv[]) {
     return t.block();
 }
 
+// The initializers are also emitted here, outside any member function.
+void f() {
+    test t{};
+}
+
 // CHECK: ![[TESTCT:[0-9]+]] = distinct !DICompositeType(tag: 
DW_TAG_structure_type, name: "test"
-// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: 
"__block_literal_1",
-// CHECK-SAME:             elements: ![[ELEMS:.*]])
-// CHECK: ![[ELEMS]] = !{{{.*}}, ![[THIS:[0-9]+]]}
-// CHECK: ![[THIS]] = !DIDerivedType(tag: DW_TAG_member, name: "this",
-// CHECK-SAME:                       baseType: ![[TESTCT]],
+// CHECK: ![[THISPTR:[0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, 
baseType: ![[TESTCT]], size: 64)
 
+// The line-5 block gets a literal type per emitting function (the constructor
+// and f), sharing the member list; the line-6 block is inside the lambda.
+// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: 
"__block_literal_{{[0-9]+}}", {{.*}} line: 5, size: 320, elements: 
![[ELEMS5:[0-9]+]])
+// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: 
"__block_literal_{{[0-9]+}}", {{.*}} line: 5, size: 320, elements: ![[ELEMS5]])
+// CHECK-DAG: ![[ELEMS5]] = !{{{.*}}, ![[THIS5:[0-9]+]]}
+// CHECK-DAG: ![[THIS5]] = !DIDerivedType(tag: DW_TAG_member, name: "this", 
{{.*}} line: 5, baseType: ![[THISPTR]], size: 64, offset: 256, flags: 
DIFlagPublic)
 
+// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: 
"__block_literal_{{[0-9]+}}", {{.*}} line: 6, size: 320, elements: 
![[ELEMS6:[0-9]+]])
+// CHECK-DAG: ![[ELEMS6]] = !{{{.*}}, ![[THIS6:[0-9]+]]}
+// CHECK-DAG: ![[THIS6]] = !DIDerivedType(tag: DW_TAG_member, name: "this", 
{{.*}} line: 6, baseType: ![[THISPTR]], size: 64, offset: 256, flags: 
DIFlagPublic)

>From fda1f36e7219e7869df3e36f4b544969b2e27c43 Mon Sep 17 00:00:00 2001
From: Akash Manna <[email protected]>
Date: Wed, 18 Nov 2026 09:16:32 +0530
Subject: [PATCH 2/3] [Clang] Record the type of a block's captured this on the
 BlockDecl

Per review: instead of inferring the type of a captured `this` in CodeGen, 
store it on `BlockDecl` (replacing the CapturesCXXThis bit), fill it from the 
Sema capture, serialize it, and read it in computeBlockInfo and the block debug 
info. CheckCXXThisCapture also applied ByCopy to every enclosing closure, so an 
enclosing lambda or block copied *this; only the requesting lambda does now.
---
 clang/docs/ReleaseNotes.md                    |  2 +-
 clang/include/clang/AST/Decl.h                |  9 +++++---
 clang/include/clang/AST/DeclBase.h            |  2 --
 clang/lib/AST/Decl.cpp                        |  5 ++--
 clang/lib/CodeGen/CGBlocks.cpp                |  5 +---
 clang/lib/CodeGen/CGBlocks.h                  |  3 ---
 clang/lib/CodeGen/CGClass.cpp                 | 23 -------------------
 clang/lib/CodeGen/CGDebugInfo.cpp             |  2 +-
 clang/lib/CodeGen/CodeGenFunction.h           | 18 ---------------
 clang/lib/Sema/SemaExpr.cpp                   |  5 +++-
 clang/lib/Sema/SemaExprCXX.cpp                |  5 ++--
 clang/lib/Sema/SemaLambda.cpp                 |  2 +-
 clang/lib/Serialization/ASTReaderDecl.cpp     |  4 ++--
 clang/lib/Serialization/ASTWriterDecl.cpp     |  2 +-
 clang/test/CodeGenCXX/blocks.cpp              |  6 +++++
 .../CodeGenCXX/cxx1z-lambda-star-this.cpp     | 13 +++++++++++
 clang/test/PCH/block-helpers.cpp              |  7 ++++++
 clang/test/PCH/block-helpers.h                |  5 ++++
 18 files changed, 53 insertions(+), 65 deletions(-)

diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index d52dce2452cc63..d0e942ac1de1d3 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -868,7 +868,7 @@ documentation](CIR/index.md) for more information regarding 
ClangIR's status and
 - Fixed an ICE that occurred when a structured binding pack is expanded 
outside the lambda where it was declared. (#GH214160)
 - Fixed a crash when a statement expression in the initializer of a 
new-expression starts with a loop or a label. (#GH175427)
 - Fixed a crash in an implicit assignment operator when a `noreturn` member or 
base `operator=` is followed by trivially copyable members. (#GH111612)
-- Fixed a crash when a block in a default member initializer captures `this` 
and the class is aggregate-initialized outside of its member functions. 
(#GH229323)
+- Fixed a crash when a block in a default member initializer captures `this` 
and the class is aggregate-initialized outside of its member functions; a 
lambda or block enclosing a `[*this]` capture no longer copies `*this` as well. 
(#GH229323)
 - Fixed a bug where a stray closing curley brace in an OpenMP/OpenACC pragma 
could cause pragma parsing issues when inside of a member function. (#GH214195)
 - Fixed a bug where preprocessor directives following comments were not 
correctly recognized when using -C. (#GH48361)
 - Fixed a crash when declaring a member template within a local class inside 
an OpenMP region. (#GH216052)
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index c73300e7816bbd..69d0cd27c6fcc7 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -4921,6 +4921,9 @@ class BlockDecl : public Decl, public DeclContext {
   unsigned ManglingNumber = 0;
   Decl *ManglingContextDecl = nullptr;
 
+  /// The type of the captured 'this' pointer; null if not captured.
+  QualType CXXThisType;
+
 protected:
   BlockDecl(DeclContext *DC, SourceLocation CaretLoc);
 
@@ -4987,8 +4990,8 @@ class BlockDecl : public Decl, public DeclContext {
   capture_const_iterator capture_begin() const { return captures().begin(); }
   capture_const_iterator capture_end() const { return captures().end(); }
 
-  bool capturesCXXThis() const { return BlockDeclBits.CapturesCXXThis; }
-  void setCapturesCXXThis(bool B = true) { BlockDeclBits.CapturesCXXThis = B; }
+  bool capturesCXXThis() const { return !CXXThisType.isNull(); }
+  QualType getCXXThisType() const { return CXXThisType; }
 
   bool blockMissingReturnType() const {
     return BlockDeclBits.BlockMissingReturnType;
@@ -5019,7 +5022,7 @@ class BlockDecl : public Decl, public DeclContext {
   bool capturesVariable(const VarDecl *var) const;
 
   void setCaptures(ASTContext &Context, ArrayRef<Capture> Captures,
-                   bool CapturesCXXThis);
+                   QualType CXXThisType);
 
   unsigned getBlockManglingNumber() const { return ManglingNumber; }
 
diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 317486e9c4ec6a..44caeae238d282 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -1995,8 +1995,6 @@ class DeclContext {
     LLVM_PREFERRED_TYPE(bool)
     uint64_t IsVariadic : 1;
     LLVM_PREFERRED_TYPE(bool)
-    uint64_t CapturesCXXThis : 1;
-    LLVM_PREFERRED_TYPE(bool)
     uint64_t BlockMissingReturnType : 1;
     LLVM_PREFERRED_TYPE(bool)
     uint64_t IsConversionFromLambda : 1;
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 3fc5eed34dc617..3147cdf8afab86 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -5573,7 +5573,6 @@ unsigned RecordDecl::getODRHash() {
 BlockDecl::BlockDecl(DeclContext *DC, SourceLocation CaretLoc)
     : Decl(Block, DC, CaretLoc), DeclContext(Block) {
   setIsVariadic(false);
-  setCapturesCXXThis(false);
   setBlockMissingReturnType(true);
   setIsConversionFromLambda(false);
   setDoesNotEscape(false);
@@ -5592,8 +5591,8 @@ void BlockDecl::setParams(ArrayRef<ParmVarDecl *> 
NewParamInfo) {
 }
 
 void BlockDecl::setCaptures(ASTContext &Context, ArrayRef<Capture> Captures,
-                            bool CapturesCXXThis) {
-  this->setCapturesCXXThis(CapturesCXXThis);
+                            QualType CXXThisType) {
+  this->CXXThisType = CXXThisType;
   this->NumCaptures = Captures.size();
 
   if (Captures.empty()) {
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index fdfd39c9dffb17..ba385b27c01917 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -582,10 +582,7 @@ static void computeBlockInfo(CodeGenModule &CGM, 
CodeGenFunction *CGF,
 
   // First, 'this'.
   if (block->capturesCXXThis()) {
-    assert(CGF && "Can't capture 'this' in a global block");
-    QualType thisType = CGF->getCXXThisType();
-    assert(!thisType.isNull() && "No 'this' to capture here");
-    info.CXXThisType = thisType;
+    QualType thisType = block->getCXXThisType();
 
     // Theoretically, this could be in a different address space, so
     // don't assume standard pointer size/align.
diff --git a/clang/lib/CodeGen/CGBlocks.h b/clang/lib/CodeGen/CGBlocks.h
index 73240fe1f65318..b2e850046ab9af 100644
--- a/clang/lib/CodeGen/CGBlocks.h
+++ b/clang/lib/CodeGen/CGBlocks.h
@@ -281,9 +281,6 @@ class CGBlockInfo {
   CharUnits BlockAlign;
   CharUnits CXXThisOffset;
 
-  /// The type of the captured 'this', if there is one.
-  QualType CXXThisType;
-
   // Offset of the gap caused by block header having a smaller
   // alignment than the alignment of the block descriptor. This
   // is the gap offset before the first capturued field.
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index 507fafe3ebe015..a1b61394571d47 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -146,29 +146,6 @@ Address CodeGenFunction::LoadCXXThisAddress() {
       false, nullptr, nullptr, KnownNonNull);
 }
 
-QualType CodeGenFunction::getCXXThisType() const {
-  if (!CXXThisTypeOverride.isNull())
-    return CXXThisTypeOverride;
-
-  // A lambda capturing '*this' by copy points 'this' at the copy.
-  if (LambdaThisCaptureField) {
-    QualType FieldTy = LambdaThisCaptureField->getType();
-    return FieldTy->isPointerType() ? FieldTy
-                                    : getContext().getPointerType(FieldTy);
-  }
-
-  if (BlockInfo && BlockInfo->getBlockDecl()->capturesCXXThis())
-    return BlockInfo->CXXThisType;
-  if (CapturedStmtInfo && CapturedStmtInfo->isCXXThisExprCaptured())
-    return CapturedStmtInfo->getThisFieldDecl()->getType();
-
-  if (const auto *MD = dyn_cast_if_present<CXXMethodDecl>(CurFuncDecl);
-      MD && MD->isImplicitObjectMemberFunction())
-    return MD->getThisType();
-
-  return QualType();
-}
-
 /// Emit the address of a field using a member data pointer.
 ///
 /// \param E Only used for emergency diagnostics
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 317cf3eabf991c..f2ced5c616fe7a 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -6048,7 +6048,7 @@ void 
CGDebugInfo::EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
 
     // If we have a null capture, this must be the C++ 'this' capture.
     if (!capture) {
-      fields.push_back(createFieldType("this", block.CXXThisType, loc,
+      fields.push_back(createFieldType("this", blockDecl->getCXXThisType(), 
loc,
                                        AS_public, offsetInBits, tunit, tunit));
       continue;
     }
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index 676459e324debd..f3c3ef3b94da0a 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -1900,25 +1900,19 @@ class CodeGenFunction : public CodeGenTypeCache {
     CXXDefaultInitExprScope(CodeGenFunction &CGF, const CXXDefaultInitExpr *E)
         : CGF(CGF), OldCXXThisValue(CGF.CXXThisValue),
           OldCXXThisAlignment(CGF.CXXThisAlignment),
-          OldCXXThisTypeOverride(CGF.CXXThisTypeOverride),
           SourceLocScope(E, CGF.CurSourceLocExprScope) {
       CGF.CXXThisValue = CGF.CXXDefaultInitExprThis.getBasePointer();
       CGF.CXXThisAlignment = CGF.CXXDefaultInitExprThis.getAlignment();
-      // [expr.prim.general]p4: 'this' is "pointer to X" in X's initializers.
-      CGF.CXXThisTypeOverride = CGF.getContext().getPointerType(
-          CGF.getContext().getCanonicalTagType(E->getField()->getParent()));
     }
     ~CXXDefaultInitExprScope() {
       CGF.CXXThisValue = OldCXXThisValue;
       CGF.CXXThisAlignment = OldCXXThisAlignment;
-      CGF.CXXThisTypeOverride = OldCXXThisTypeOverride;
     }
 
   public:
     CodeGenFunction &CGF;
     llvm::Value *OldCXXThisValue;
     CharUnits OldCXXThisAlignment;
-    QualType OldCXXThisTypeOverride;
     SourceLocExprScopeGuard SourceLocScope;
   };
 
@@ -1952,7 +1946,6 @@ class CodeGenFunction : public CodeGenTypeCache {
           OldCXXThisValue(CGF.CXXThisValue),
           OldCXXABIThisAlignment(CGF.CXXABIThisAlignment),
           OldCXXThisAlignment(CGF.CXXThisAlignment),
-          OldCXXThisTypeOverride(CGF.CXXThisTypeOverride),
           OldReturnValue(CGF.ReturnValue), OldFnRetTy(CGF.FnRetTy),
           OldCXXInheritedCtorInitExprArgs(
               std::move(CGF.CXXInheritedCtorInitExprArgs)) {
@@ -1964,7 +1957,6 @@ class CodeGenFunction : public CodeGenTypeCache {
       CGF.CXXThisValue = nullptr;
       CGF.CXXABIThisAlignment = CharUnits();
       CGF.CXXThisAlignment = CharUnits();
-      CGF.CXXThisTypeOverride = QualType();
       CGF.ReturnValue = Address::invalid();
       CGF.FnRetTy = QualType();
       CGF.CXXInheritedCtorInitExprArgs.clear();
@@ -1978,7 +1970,6 @@ class CodeGenFunction : public CodeGenTypeCache {
       CGF.CXXThisValue = OldCXXThisValue;
       CGF.CXXABIThisAlignment = OldCXXABIThisAlignment;
       CGF.CXXThisAlignment = OldCXXThisAlignment;
-      CGF.CXXThisTypeOverride = OldCXXThisTypeOverride;
       CGF.ReturnValue = OldReturnValue;
       CGF.FnRetTy = OldFnRetTy;
       CGF.CXXInheritedCtorInitExprArgs =
@@ -1995,7 +1986,6 @@ class CodeGenFunction : public CodeGenTypeCache {
     llvm::Value *OldCXXThisValue;
     CharUnits OldCXXABIThisAlignment;
     CharUnits OldCXXThisAlignment;
-    QualType OldCXXThisTypeOverride;
     Address OldReturnValue;
     QualType OldFnRetTy;
     CallArgList OldCXXInheritedCtorInitExprArgs;
@@ -2197,10 +2187,6 @@ class CodeGenFunction : public CodeGenTypeCache {
   /// this expression.
   Address CXXDefaultInitExprThis = Address::invalid();
 
-  /// The type of 'this' while evaluating a CXXDefaultInitExpr: a pointer to
-  /// the class being initialized, which need not be CurFuncDecl's class.
-  QualType CXXThisTypeOverride;
-
   /// The current array initialization index when evaluating an
   /// ArrayInitIndexExpr within an ArrayInitLoopExpr.
   llvm::Value *ArrayInitIndex = nullptr;
@@ -3285,10 +3271,6 @@ class CodeGenFunction : public CodeGenTypeCache {
   }
   Address LoadCXXThisAddress();
 
-  /// Return the type of the pointer LoadCXXThis() returns, or null if there is
-  /// no 'this' here.
-  QualType getCXXThisType() const;
-
   /// LoadCXXVTT - Load the VTT parameter to base constructors/destructors have
   /// virtual bases.
   // FIXME: Every place that calls LoadCXXVTT is something
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 873ad8d8e1cb92..ca95755d4423fa 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -17548,7 +17548,10 @@ ExprResult Sema::ActOnBlockStmtExpr(SourceLocation 
CaretLoc,
                               CopyExpr);
     Captures.push_back(NewCap);
   }
-  BD->setCaptures(Context, Captures, BSI->CXXThisCaptureIndex != 0);
+  QualType CXXThisType;
+  if (BSI->isCXXThisCaptured())
+    CXXThisType = BSI->getCXXThisCapture().getCaptureType();
+  BD->setCaptures(Context, Captures, CXXThisType);
 
   // Pop the block scope now but keep it alive to the end of this function.
   AnalysisBasedWarnings::Policy WP =
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 576393d4594062..a116f7b4780e86 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1395,13 +1395,14 @@ bool Sema::CheckCXXThisCapture(SourceLocation Loc, 
const bool Explicit,
   for (int idx = MaxFunctionScopesIndex; NumCapturingClosures;
        --idx, --NumCapturingClosures) {
     CapturingScopeInfo *CSI = cast<CapturingScopeInfo>(FunctionScopes[idx]);
+    bool CaptureByCopy = ByCopy && idx == MaxFunctionScopesIndex;
 
     // The type of the corresponding data member (not a 'this' pointer if 'by
     // copy').
-    QualType CaptureType = ByCopy ? ThisTy->getPointeeType() : ThisTy;
+    QualType CaptureType = CaptureByCopy ? ThisTy->getPointeeType() : ThisTy;
 
     bool isNested = NumCapturingClosures > 1;
-    CSI->addThisCapture(isNested, Loc, CaptureType, ByCopy);
+    CSI->addThisCapture(isNested, Loc, CaptureType, CaptureByCopy);
   }
   return false;
 }
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index 970591d4801112..08526b7ec22b83 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -2486,7 +2486,7 @@ ExprResult 
Sema::BuildBlockForLambdaConversion(SourceLocation CurrentLocation,
                                     SC_None);
   BlockDecl::Capture Capture(/*variable=*/CapVar, /*byRef=*/false,
                              /*nested=*/false, /*copy=*/Init.get());
-  Block->setCaptures(Context, Capture, /*CapturesCXXThis=*/false);
+  Block->setCaptures(Context, Capture, /*CXXThisType=*/QualType());
 
   // Add a fake function body to the block. IR generation is responsible
   // for filling in the actual body, which cannot be expressed as an AST.
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index 145a2663424644..9412fe77abc2a9 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -1812,7 +1812,7 @@ void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
   BD->setDoesNotEscape(Record.readInt());
   BD->setCanAvoidCopyToHeap(Record.readInt());
 
-  bool capturesCXXThis = Record.readInt();
+  QualType CXXThisType = Record.readType();
   unsigned numCaptures = Record.readInt();
   SmallVector<BlockDecl::Capture, 16> captures;
   captures.reserve(numCaptures);
@@ -1825,7 +1825,7 @@ void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
 
     captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr));
   }
-  BD->setCaptures(Reader.getContext(), captures, capturesCXXThis);
+  BD->setCaptures(Reader.getContext(), captures, CXXThisType);
 }
 
 void ASTDeclReader::VisitOutlinedFunctionDecl(OutlinedFunctionDecl *D) {
diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp 
b/clang/lib/Serialization/ASTWriterDecl.cpp
index bd8bc046f2874b..11a4be65ee4a21 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -1474,7 +1474,7 @@ void ASTDeclWriter::VisitBlockDecl(BlockDecl *D) {
   Record.push_back(D->isConversionFromLambda());
   Record.push_back(D->doesNotEscape());
   Record.push_back(D->canAvoidCopyToHeap());
-  Record.push_back(D->capturesCXXThis());
+  Record.AddTypeRef(D->getCXXThisType());
   Record.push_back(D->getNumCaptures());
   for (const auto &capture : D->captures()) {
     Record.AddDeclRef(capture.getVariable());
diff --git a/clang/test/CodeGenCXX/blocks.cpp b/clang/test/CodeGenCXX/blocks.cpp
index 5f35889f344504..a2099b22fac92a 100644
--- a/clang/test/CodeGenCXX/blocks.cpp
+++ b/clang/test/CodeGenCXX/blocks.cpp
@@ -291,6 +291,7 @@ namespace test11 {
     int func();
     int (^nested)() = ^{ return ^{ return func(); }(); };
     int viaLambda = [this] { return ^{ return func(); }(); }();
+    void m();
   };
   struct Other {
     int y;
@@ -348,6 +349,11 @@ namespace test11 {
   // CHECK:       [[THIS:%.*]] = load ptr, ptr
   // CHECK-NEXT:  call noundef i32 @_ZN6test111B4funcEv(ptr {{[^,]*}} [[THIS]])
 
+  // A block around a lambda that copies '*this' still captures the pointer.
+  // CHECK-LABEL: define{{.*}} void @_ZN6test111B1mEv(
+  // CHECK:       alloca <{ ptr, i32, i32, ptr, ptr, ptr }>,
+  void B::m() { ^{ return [*this]() mutable { return func(); }(); }(); }
+
   // CHECK-LABEL: define internal void @__cxx_global_var_init()
   // CHECK:       store ptr @_ZN6test112gaE, ptr
   A ga{};
diff --git a/clang/test/CodeGenCXX/cxx1z-lambda-star-this.cpp 
b/clang/test/CodeGenCXX/cxx1z-lambda-star-this.cpp
index a89b2a3ddd2f64..8cc0f3b9ab251d 100644
--- a/clang/test/CodeGenCXX/cxx1z-lambda-star-this.cpp
+++ b/clang/test/CodeGenCXX/cxx1z-lambda-star-this.cpp
@@ -27,3 +27,16 @@ int X = B{}.bar()();
 //CHECK: @"?bar@B@@QAE?A?<auto>@@XZ"(ptr {{[^,]*}} %this, ptr dead_on_unwind 
noalias writable sret(%class.anon.0) align 4 %agg.result)
 //CHECK: %[[I20:.+]] = getelementptr inbounds nuw %class.anon.0, ptr 
%agg.result, i32 0, i32 0
 //CHECK: store ptr %this1, ptr %[[I20]], align 4
+
+struct C {
+  double c = 333;
+  auto baz() { return [&] { return [*this] { return c; }(); }; }
+};
+
+namespace ns3 {
+int X = C{}.baz()();
+}
+// The enclosing lambda captures 'this'; only the inner one copies '*this'.
+//CHECK: @"?baz@C@@QAE?A?<auto>@@XZ"(ptr {{[^,]*}} %this, ptr dead_on_unwind 
noalias writable sret(%class.anon.1) align 4 %agg.result)
+//CHECK: %[[I30:.+]] = getelementptr inbounds nuw %class.anon.1, ptr 
%agg.result, i32 0, i32 0
+//CHECK: store ptr %this1, ptr %[[I30]], align 4
diff --git a/clang/test/PCH/block-helpers.cpp b/clang/test/PCH/block-helpers.cpp
index 89d3967566168f..ba9fd665ed5d0f 100644
--- a/clang/test/PCH/block-helpers.cpp
+++ b/clang/test/PCH/block-helpers.cpp
@@ -26,7 +26,14 @@
 // CHECK: call void @_Block_object_dispose(
 
 // CHECK-LABEL: define linkonce_odr hidden void 
@__destroy_helper_block_e8_32r40r(
+
+// The block captures 'this'; its type comes from the PCH.
+// CHECK-LABEL: define internal noundef i32 @___ZN1T1nEv_block_invoke(
+// CHECK: %[[THIS:.*]] = load ptr, ptr %block.captured-this
+// CHECK: getelementptr inbounds nuw %struct.T, ptr %[[THIS]], i32 0, i32 0
 void test() {
   S s;
   s.m();
+  T t;
+  t.n();
 }
diff --git a/clang/test/PCH/block-helpers.h b/clang/test/PCH/block-helpers.h
index 3614cc7be93a06..e9c56c9b9982cd 100644
--- a/clang/test/PCH/block-helpers.h
+++ b/clang/test/PCH/block-helpers.h
@@ -10,3 +10,8 @@ struct S {
     ^{ (void)x; (void)y; };
   }
 };
+
+struct T {
+  int x;
+  int n() { return ^{ return x; }(); }
+};

>From f38794996bd6e15079ec10687c75bd0e28ae3108 Mon Sep 17 00:00:00 2001
From: Akash Manna <[email protected]>
Date: Thu, 19 Nov 2026 00:11:06 +0530
Subject: [PATCH 3/3] [Clang] Keep the lambda capture change out of this PR

Per review, only an enclosing block or captured region is kept from being 
marked as capturing `*this` by copy; lambda captures are unchanged here. The 
lambda test and release-note clause are dropped.
---
 clang/docs/ReleaseNotes.md                       |  2 +-
 clang/lib/Sema/SemaExprCXX.cpp                   |  3 ++-
 clang/test/CodeGenCXX/cxx1z-lambda-star-this.cpp | 13 -------------
 3 files changed, 3 insertions(+), 15 deletions(-)

diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index d0e942ac1de1d3..d52dce2452cc63 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -868,7 +868,7 @@ documentation](CIR/index.md) for more information regarding 
ClangIR's status and
 - Fixed an ICE that occurred when a structured binding pack is expanded 
outside the lambda where it was declared. (#GH214160)
 - Fixed a crash when a statement expression in the initializer of a 
new-expression starts with a loop or a label. (#GH175427)
 - Fixed a crash in an implicit assignment operator when a `noreturn` member or 
base `operator=` is followed by trivially copyable members. (#GH111612)
-- Fixed a crash when a block in a default member initializer captures `this` 
and the class is aggregate-initialized outside of its member functions; a 
lambda or block enclosing a `[*this]` capture no longer copies `*this` as well. 
(#GH229323)
+- Fixed a crash when a block in a default member initializer captures `this` 
and the class is aggregate-initialized outside of its member functions. 
(#GH229323)
 - Fixed a bug where a stray closing curley brace in an OpenMP/OpenACC pragma 
could cause pragma parsing issues when inside of a member function. (#GH214195)
 - Fixed a bug where preprocessor directives following comments were not 
correctly recognized when using -C. (#GH48361)
 - Fixed a crash when declaring a member template within a local class inside 
an OpenMP region. (#GH216052)
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index a116f7b4780e86..e708de6981a54c 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1395,7 +1395,8 @@ bool Sema::CheckCXXThisCapture(SourceLocation Loc, const 
bool Explicit,
   for (int idx = MaxFunctionScopesIndex; NumCapturingClosures;
        --idx, --NumCapturingClosures) {
     CapturingScopeInfo *CSI = cast<CapturingScopeInfo>(FunctionScopes[idx]);
-    bool CaptureByCopy = ByCopy && idx == MaxFunctionScopesIndex;
+    // An enclosing block or captured region can only capture the pointer.
+    bool CaptureByCopy = ByCopy && isa<LambdaScopeInfo>(CSI);
 
     // The type of the corresponding data member (not a 'this' pointer if 'by
     // copy').
diff --git a/clang/test/CodeGenCXX/cxx1z-lambda-star-this.cpp 
b/clang/test/CodeGenCXX/cxx1z-lambda-star-this.cpp
index 8cc0f3b9ab251d..a89b2a3ddd2f64 100644
--- a/clang/test/CodeGenCXX/cxx1z-lambda-star-this.cpp
+++ b/clang/test/CodeGenCXX/cxx1z-lambda-star-this.cpp
@@ -27,16 +27,3 @@ int X = B{}.bar()();
 //CHECK: @"?bar@B@@QAE?A?<auto>@@XZ"(ptr {{[^,]*}} %this, ptr dead_on_unwind 
noalias writable sret(%class.anon.0) align 4 %agg.result)
 //CHECK: %[[I20:.+]] = getelementptr inbounds nuw %class.anon.0, ptr 
%agg.result, i32 0, i32 0
 //CHECK: store ptr %this1, ptr %[[I20]], align 4
-
-struct C {
-  double c = 333;
-  auto baz() { return [&] { return [*this] { return c; }(); }; }
-};
-
-namespace ns3 {
-int X = C{}.baz()();
-}
-// The enclosing lambda captures 'this'; only the inner one copies '*this'.
-//CHECK: @"?baz@C@@QAE?A?<auto>@@XZ"(ptr {{[^,]*}} %this, ptr dead_on_unwind 
noalias writable sret(%class.anon.1) align 4 %agg.result)
-//CHECK: %[[I30:.+]] = getelementptr inbounds nuw %class.anon.1, ptr 
%agg.result, i32 0, i32 0
-//CHECK: store ptr %this1, ptr %[[I30]], align 4

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to