[PATCH] D45438: [CodeView] Enable debugging of captured variables within C++ lambdas
Brock Wyma via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 9 06:31:29 PDT 2018
bwyma created this revision.
bwyma added reviewers: rnk, zturner, smerritt.
Herald added subscribers: JDevlieghere, aprantl.
When emitting CodeView debug information, C++ lambda types need a unique identifier so Visual Studio can match the forward reference for the type to the definition. Currently they are all named "<unnamed-tag>". This patch, combined with https://reviews.llvm.org/D32498, will enable debugging of captured variables within lambdas using Visual Studio.
Previous LF_CLASS type record for a lambda looks like this:
Class (0x100A) {
TypeLeafKind: LF_CLASS (0x1504)
...
Name: main::<unnamed-tag>
}
After this change the type record looks like this:
Class (0x100A) {
TypeLeafKind: LF_CLASS (0x1504)
...
Name: main::<unnamed-tag>
LinkageName: .?AV<lambda_0>@?0??main@@9@
}
Manufacturing a better "name" for the lambda object is not necessary to allow proper debugging of captured variables.
https://reviews.llvm.org/D45438
Files:
llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp
llvm/tools/clang/test/CodeGenCXX/debug-info-lamda.cpp
Index: llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp
+++ llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -799,15 +799,21 @@
}
}
+static bool isCodeViewCXXLambda(const TagDecl *TD, CodeGenModule& CGM) {
+ const auto *CXXDecl = dyn_cast<CXXRecordDecl>(TD);
+ return CGM.getCodeGenOpts().EmitCodeView && CXXDecl && CXXDecl->isLambda();
+}
+
/// In C++ mode, types have linkage, so we can rely on the ODR and
-/// on their mangled names, if they're external.
+/// on their mangled names, if they're external or a CodeView C++ Lambda.
static SmallString<256> getUniqueTagTypeName(const TagType *Ty,
CodeGenModule &CGM,
llvm::DICompileUnit *TheCU) {
SmallString<256> FullName;
const TagDecl *TD = Ty->getDecl();
- if (!hasCXXMangling(TD, TheCU) || !TD->isExternallyVisible())
+ if (!hasCXXMangling(TD, TheCU) ||
+ (!TD->isExternallyVisible() && !isCodeViewCXXLambda(TD, CGM)))
return FullName;
// TODO: This is using the RTTI name. Is there a better way to get
Index: llvm/tools/clang/test/CodeGenCXX/debug-info-lamda.cpp
===================================================================
--- llvm/tools/clang/test/CodeGenCXX/debug-info-lamda.cpp
+++ llvm/tools/clang/test/CodeGenCXX/debug-info-lamda.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -debug-info-kind=limited -S -emit-llvm -std=c++11 -o - %s | FileCheck --check-prefix LINUX %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -debug-info-kind=limited -gcodeview -S -emit-llvm -std=c++11 -o - %s | FileCheck --check-prefix MSVC %s
+
+int main(int argc, char* argv[], char* arge[]) {
+ auto lambda = [argc](int count) -> int { return argc == count ? 1 : 0; };
+ return lambda(0);
+}
+
+// LINUX: !DICompositeType(tag: DW_TAG_class_type
+// LINUX-NOT: name:
+// LINUX-NOT: identifier:
+// LINUX-SAME: )
+//
+// MSVC: define{{.*}} i32 @"??R<lambda_0>@?0??main@@9 at QEBA@H at Z"
+// MSVC: !DICompositeType(tag: DW_TAG_class_type
+// MSVC-NOT: name:
+// MSVC-SAME: identifier: ".?AV<lambda_0>@?0??main@@9@"
+// MSVC-SAME: )
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45438.141628.patch
Type: text/x-patch
Size: 2245 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180409/7d68c4b8/attachment-0001.bin>
More information about the llvm-commits
mailing list