https://github.com/ayushpareek2003 created 
https://github.com/llvm/llvm-project/pull/149674

Fix an issue where local lambdas caused a crash when importing the std module 
in LLDB due to missing capture fields in debug info.  
Now closures always emit all fields for lambdas by skipping the `isImplicit` 
check.  
This unblocks libc++ from using local lambdas freely


>From c1e04fa46a8375f6865f0f7e3e9eab51fa5790d1 Mon Sep 17 00:00:00 2001
From: Ayush Pareek <ayushpareek1...@gmail.com>
Date: Sun, 20 Jul 2025 02:04:19 +0530
Subject: [PATCH] fix-149477

---
 clang/lib/CodeGen/CGDebugInfo.cpp | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index e24c68ed02865..a8f9e3e028e9f 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4187,6 +4187,32 @@ llvm::DICompositeType 
*CGDebugInfo::CreateLimitedType(const RecordType *Ty) {
   RegionMap[Ty->getDecl()].reset(RealDecl);
   TypeCache[QualType(Ty, 0).getAsOpaquePtr()].reset(RealDecl);
 
+  if (const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
+    SmallVector<llvm::Metadata *, 16> EltTys;
+    const ASTRecordLayout &Layout = CGM.getContext().getASTRecordLayout(CXXRD);
+
+    for (const FieldDecl *Field : CXXRD->fields()) {
+      if (!CXXRD->isLambda() && Field->isImplicit())
+        continue;
+
+      llvm::DIType *FieldType = getOrCreateType(Field->getType(), DefUnit);
+      unsigned FieldLine = getLineNumber(Field->getLocation());
+      uint64_t FieldOffset = Layout.getFieldOffset(Field->getFieldIndex());
+      llvm::DIFile *FieldFile = DefUnit;
+
+      llvm::DIDerivedType *Elem = DBuilder.createMemberType(
+          RealDecl, Field->getName(), FieldFile, FieldLine,
+          CGM.getContext().getTypeSize(Field->getType()),
+          getTypeAlignIfRequired(Field->getType(), CGM.getContext()),
+          FieldOffset,
+          getAccessFlag(Field->getAccess()), FieldType);
+
+      EltTys.push_back(Elem);
+    }
+    // Attach the fields.
+    DBuilder.replaceArrays(RealDecl, DBuilder.getOrCreateArray(EltTys));
+  }
+
   if (const auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD))
     DBuilder.replaceArrays(RealDecl, llvm::DINodeArray(),
                            CollectCXXTemplateParams(TSpecial, DefUnit));

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to