diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 0b52d99ad07f16..3b4932cc4a30f6 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 00000000000000..0a2f08ea4aa6d8 --- /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)