Skip to content

Commit

Permalink
Supports viewing class member variables in lambda when using the vs d…
Browse files Browse the repository at this point in the history
…ebugger (llvm#71564)

Use "__this" in DataMemberRecord, make vs debugger can be parsed normally

Fixes llvm#71562
  • Loading branch information
GkvJwa authored Nov 21, 2023
1 parent d82b521 commit 7c3c243
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
4 changes: 3 additions & 1 deletion clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 27 additions & 0 deletions clang/test/CodeGenCXX/debug-info-lambda-this.cpp
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 7c3c243

Please sign in to comment.