[clang] Supports viewing class member variables in lambda when using the vs debugger (PR #71564)

via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 16 08:56:05 PST 2023


https://github.com/GkvJwa updated https://github.com/llvm/llvm-project/pull/71564

>From 5a2416d3c8da7ccdc87a84283bb12e454a832b71 Mon Sep 17 00:00:00 2001
From: GkvJwa <gkvjwa at gmail.com>
Date: Wed, 8 Nov 2023 01:37:19 +0800
Subject: [PATCH] Supports viewing class member in lambda when using the vs
 debugger

Use "__this" in the DataMemberRecord when generating pdb, so that the vs debugger can parse the  member vars in lambda normally
---
 clang/lib/CodeGen/CGDebugInfo.cpp             |  4 ++-
 .../CodeGenCXX/debug-info-lambda-this.cpp     | 27 +++++++++++++++++++
 2 files changed, 30 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenCXX/debug-info-lambda-this.cpp

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 84a166d3ac3659c..774bc0eae157f49 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1657,8 +1657,10 @@ void CGDebugInfo::CollectRecordLambdaFields(
       FieldDecl *f = *Field;
       llvm::DIFile *VUnit = getOrCreateFile(f->getLocation());
       QualType type = f->getType();
+      StringRef ThisName =
+          CGM.getCodeGenOpts().EmitCodeView ? "__this" : "this";
       llvm::DIType *fieldType = createFieldType(
-          "this", type, f->getLocation(), f->getAccess(),
+          ThisName, type, f->getLocation(), f->getAccess(),
           layout.getFieldOffset(fieldno), VUnit, RecordTy, CXXDecl);
 
       elements.push_back(fieldType);
diff --git a/clang/test/CodeGenCXX/debug-info-lambda-this.cpp b/clang/test/CodeGenCXX/debug-info-lambda-this.cpp
new file mode 100644
index 000000000000000..0a2f08ea4aa6d8e
--- /dev/null
+++ b/clang/test/CodeGenCXX/debug-info-lambda-this.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 %s -std=c++11 -triple=x86_64-pc-windows-msvc -debug-info-kind=limited -gcodeview -emit-llvm -o - | FileCheck %s
+
+class Foo {
+ public:
+  void foo() {
+    int aa = 2;
+    auto f = [=] {
+      int aaa = a + aa;
+    };
+    f();
+  }
+
+ private:
+  int a = 1;
+};
+
+int main() {
+  Foo f;
+  f.foo();
+
+  return 0;
+}
+
+// CHECK: !{![[FOO_THIS:[0-9]+]], ![[FOO_AA:[0-9]+]], ![[FOO_OPERATOR:[0-9]+]]}
+// CHECK-NEXT: ![[FOO_THIS]] = !DIDerivedType(tag: DW_TAG_member, name: "__this", scope: ![[#]], file: ![[#]], line: [[#]], baseType: ![[#]], size: [[#]])
+// CHECK-NEXT: ![[FOO_AA]] = !DIDerivedType(tag: DW_TAG_member, name: "aa", scope: ![[#]], file: ![[#]], line: [[#]], baseType: ![[#]], size: [[#]], offset: [[#]])
+// CHECK-NEXT: ![[FOO_OPERATOR]] = !DISubprogram(name: "operator()", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[#]], scopeLine: [[#]], flags: DIFlagPublic | DIFlagPrototyped, spFlags: 0)



More information about the cfe-commits mailing list