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(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@?0??main@@9@QEBA@H@Z" +// MSVC: !DICompositeType(tag: DW_TAG_class_type +// MSVC-NOT: name: +// MSVC-SAME: identifier: ".?AV@?0??main@@9@" +// MSVC-SAME: )