From: Reid Kleckner Date: Tue, 8 Aug 2017 20:30:14 +0000 (+0000) Subject: [codeview] Emit nested enums and typedefs from classes X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9452fead78c99a51ad5637d75a2a97a41030ea2e;p=clang [codeview] Emit nested enums and typedefs from classes Previously we limited ourselves to only emitting nested classes, but we need other kinds of types as well. This fixes the Visual Studio STL visualizers, so that users can visualize std::string and other objects. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@310410 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 7b2ae19ecc..b55b9e391b 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -1183,13 +1183,13 @@ void CGDebugInfo::CollectRecordNormalField( elements.push_back(FieldType); } -void CGDebugInfo::CollectRecordNestedRecord( - const RecordDecl *RD, SmallVectorImpl &elements) { - QualType Ty = CGM.getContext().getTypeDeclType(RD); +void CGDebugInfo::CollectRecordNestedType( + const TypeDecl *TD, SmallVectorImpl &elements) { + QualType Ty = CGM.getContext().getTypeDeclType(TD); // Injected class names are not considered nested records. if (isa(Ty)) return; - SourceLocation Loc = RD->getLocation(); + SourceLocation Loc = TD->getLocation(); llvm::DIType *nestedType = getOrCreateType(Ty, getOrCreateFile(Loc)); elements.push_back(nestedType); } @@ -1205,9 +1205,9 @@ void CGDebugInfo::CollectRecordFields( else { const ASTRecordLayout &layout = CGM.getContext().getASTRecordLayout(record); - // Debug info for nested records is included in the member list only for + // Debug info for nested types is included in the member list only for // CodeView. - bool IncludeNestedRecords = CGM.getCodeGenOpts().EmitCodeView; + bool IncludeNestedTypes = CGM.getCodeGenOpts().EmitCodeView; // Field number for non-static fields. unsigned fieldNo = 0; @@ -1234,10 +1234,12 @@ void CGDebugInfo::CollectRecordFields( // Bump field number for next field. ++fieldNo; - } else if (const auto *nestedRec = dyn_cast(I)) - if (IncludeNestedRecords && !nestedRec->isImplicit() && - nestedRec->getDeclContext() == record) - CollectRecordNestedRecord(nestedRec, elements); + } else if (IncludeNestedTypes) { + if (const auto *nestedType = dyn_cast(I)) + if (!nestedType->isImplicit() && + nestedType->getDeclContext() == record) + CollectRecordNestedType(nestedType, elements); + } } } diff --git a/lib/CodeGen/CGDebugInfo.h b/lib/CodeGen/CGDebugInfo.h index ceb8e4dbab..36de231f05 100644 --- a/lib/CodeGen/CGDebugInfo.h +++ b/lib/CodeGen/CGDebugInfo.h @@ -278,8 +278,8 @@ class CGDebugInfo { llvm::DIFile *F, SmallVectorImpl &E, llvm::DIType *RecordTy, const RecordDecl *RD); - void CollectRecordNestedRecord(const RecordDecl *RD, - SmallVectorImpl &E); + void CollectRecordNestedType(const TypeDecl *RD, + SmallVectorImpl &E); void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile *F, SmallVectorImpl &E, llvm::DICompositeType *RecordTy); diff --git a/test/CodeGenCXX/debug-info-codeview-nested-types.cpp b/test/CodeGenCXX/debug-info-codeview-nested-types.cpp new file mode 100644 index 0000000000..7c8f78e7a0 --- /dev/null +++ b/test/CodeGenCXX/debug-info-codeview-nested-types.cpp @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 %s -std=c++11 -triple=x86_64-pc-windows-msvc -debug-info-kind=limited -gcodeview -emit-llvm -o - | FileCheck %s + +struct HasNested { + enum InnerEnum { _BUF_SIZE = 1 }; + typedef int InnerTypedef; + enum { InnerEnumerator = 2 }; + struct InnerStruct { }; +}; +HasNested f; + +// CHECK: ![[INNERENUM:[0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "InnerEnum", {{.*}}) +// CHECK: ![[HASNESTED:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "HasNested", +// CHECK-SAME: elements: ![[MEMBERS:[0-9]+]], +// +// CHECK: ![[MEMBERS]] = !{![[INNERENUM]], ![[INNERTYPEDEF:[0-9]+]], ![[UNNAMEDENUM:[0-9]+]], ![[INNERSTRUCT:[0-9]+]]} +// +// CHECK: ![[INNERTYPEDEF]] = !DIDerivedType(tag: DW_TAG_typedef, name: "InnerTypedef", scope: ![[HASNESTED]]{{.*}}) +// +// CHECK: ![[UNNAMEDENUM]] = !DICompositeType(tag: DW_TAG_enumeration_type, scope: ![[HASNESTED]], +// CHECK-SAME: elements: ![[UNNAMEDMEMBERS:[0-9]+]], +// CHECK: ![[UNNAMEDMEMBERS]] = !{![[INNERENUMERATOR:[0-9]+]]} +// CHECK: ![[INNERENUMERATOR]] = !DIEnumerator(name: "InnerEnumerator", value: 2) +// +// CHECK: ![[INNERSTRUCT]] = !DICompositeType(tag: DW_TAG_structure_type, name: "InnerStruct" +// CHECK-SAME: flags: DIFlagFwdDecl