From: Adrian McCarthy Date: Thu, 21 Jul 2016 13:16:14 +0000 (+0000) Subject: Include unreferenced nested types in member list only for CodeView X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=86087031dabdda4e70e1e5cf0b26f8ab8d3b1736;p=clang Include unreferenced nested types in member list only for CodeView Unreferenced nested structs and classes were omitted from the debug info. In DWARF, this was intentional, to avoid bloat. But for CodeView, we want this information to be consistent with what Microsoft tools would produce and expect. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@276271 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 5e9d73f082..9763e9b51a 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -1090,6 +1090,14 @@ void CGDebugInfo::CollectRecordNormalField( elements.push_back(FieldType); } +void CGDebugInfo::CollectRecordNestedRecord( + const RecordDecl *RD, SmallVectorImpl &elements) { + QualType Ty = CGM.getContext().getTypeDeclType(RD); + SourceLocation Loc = RD->getLocation(); + llvm::DIType *nestedType = getOrCreateType(Ty, getOrCreateFile(Loc)); + elements.push_back(nestedType); +} + void CGDebugInfo::CollectRecordFields( const RecordDecl *record, llvm::DIFile *tunit, SmallVectorImpl &elements, @@ -1101,6 +1109,10 @@ void CGDebugInfo::CollectRecordFields( else { const ASTRecordLayout &layout = CGM.getContext().getASTRecordLayout(record); + // Debug info for nested records is included in the member list only for + // CodeView. + bool IncludeNestedRecords = CGM.getCodeGenOpts().EmitCodeView; + // Field number for non-static fields. unsigned fieldNo = 0; @@ -1126,7 +1138,10 @@ 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); } } @@ -3620,8 +3635,8 @@ void CGDebugInfo::EmitUsingDirective(const UsingDirectiveDecl &UD) { if (CGM.getCodeGenOpts().getDebugInfo() < codegenoptions::LimitedDebugInfo) return; const NamespaceDecl *NSDecl = UD.getNominatedNamespace(); - if (!NSDecl->isAnonymousNamespace() || - CGM.getCodeGenOpts().DebugExplicitImport) { + if (!NSDecl->isAnonymousNamespace() || + CGM.getCodeGenOpts().DebugExplicitImport) { DBuilder.createImportedModule( getCurrentContextDescriptor(cast(UD.getDeclContext())), getOrCreateNameSpace(NSDecl), diff --git a/lib/CodeGen/CGDebugInfo.h b/lib/CodeGen/CGDebugInfo.h index 366dd81ac8..70c1646296 100644 --- a/lib/CodeGen/CGDebugInfo.h +++ b/lib/CodeGen/CGDebugInfo.h @@ -254,6 +254,8 @@ class CGDebugInfo { llvm::DIFile *F, SmallVectorImpl &E, llvm::DIType *RecordTy, const RecordDecl *RD); + void CollectRecordNestedRecord(const RecordDecl *RD, + SmallVectorImpl &E); void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile *F, SmallVectorImpl &E, llvm::DICompositeType *RecordTy); diff --git a/test/CodeGenCXX/debug-info-dup-fwd-decl.cpp b/test/CodeGenCXX/debug-info-dup-fwd-decl.cpp index f7a2cfe7ba..3b23ebf7de 100644 --- a/test/CodeGenCXX/debug-info-dup-fwd-decl.cpp +++ b/test/CodeGenCXX/debug-info-dup-fwd-decl.cpp @@ -19,6 +19,6 @@ protected: Test t; -// CHECK: !DIDerivedType(tag: DW_TAG_pointer_type // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "data" +// CHECK: !DIDerivedType(tag: DW_TAG_pointer_type // CHECK-NOT: !DICompositeType(tag: DW_TAG_structure_type, name: "data" diff --git a/test/CodeGenCXX/debug-info-ms-abi.cpp b/test/CodeGenCXX/debug-info-ms-abi.cpp index a146ce9417..b1ce128e0f 100644 --- a/test/CodeGenCXX/debug-info-ms-abi.cpp +++ b/test/CodeGenCXX/debug-info-ms-abi.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -triple=i686-pc-windows-msvc -debug-info-kind=limited -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 %s -triple=i686-pc-windows-msvc -debug-info-kind=limited -gcodeview -emit-llvm -o - | FileCheck %s // Tests that certain miscellaneous features work in the MS ABI. @@ -12,19 +12,22 @@ Foo f; Foo::Nested n; // CHECK: ![[Foo:[^ ]*]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo", +// CHECK-SAME: elements: ![[elements:[0-9]+]] // CHECK-SAME: identifier: ".?AUFoo@@" -// CHECK: !DISubprogram(name: "f", +// CHECK: ![[elements]] = !{![[vptr:[0-9]+]], ![[Nested:[0-9]+]], ![[f:[0-9]+]], ![[g:[0-9]+]], ![[h:[0-9]+]]} + +// CHECK: ![[Nested]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Nested", +// CHECK-SAME: identifier: ".?AUNested@Foo@@" + +// CHECK: ![[f]] = !DISubprogram(name: "f", // CHECK-SAME: containingType: ![[Foo]], virtuality: DW_VIRTUALITY_virtual, virtualIndex: 0, // CHECK-SAME: flags: DIFlagPrototyped | DIFlagIntroducedVirtual, -// CHECK: !DISubprogram(name: "g", +// CHECK: ![[g]] = !DISubprogram(name: "g", // CHECK-SAME: containingType: ![[Foo]], virtuality: DW_VIRTUALITY_virtual, virtualIndex: 1, // CHECK-SAME: flags: DIFlagPrototyped | DIFlagIntroducedVirtual, -// CHECK: !DISubprogram(name: "h", +// CHECK: ![[h]] = !DISubprogram(name: "h", // CHECK-SAME: containingType: ![[Foo]], virtuality: DW_VIRTUALITY_virtual, virtualIndex: 2, // CHECK-SAME: flags: DIFlagPrototyped | DIFlagIntroducedVirtual, - -// CHECK: distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Nested", -// CHECK-SAME: identifier: ".?AUNested@Foo@@" diff --git a/test/Modules/ModuleDebugInfo.cpp b/test/Modules/ModuleDebugInfo.cpp index 998d36327e..a190a04e33 100644 --- a/test/Modules/ModuleDebugInfo.cpp +++ b/test/Modules/ModuleDebugInfo.cpp @@ -121,7 +121,7 @@ // CHECK-SAME: flags: DIFlagFwdDecl, // CHECK-SAME: identifier: "_ZTS9Template1IPvE") -// Explicit instatiation. +// Explicit instantiation. // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "Template1", // CHECK-SAME: templateParams: // CHECK-SAME: identifier: "_ZTS9Template1IiE") @@ -130,6 +130,10 @@ // CHECK-SAME: flags: DIFlagFwdDecl // CHECK-SAME: identifier: "_ZTS15FwdDeclTemplateIiE") +// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Member", +// CHECK-SAME: flags: DIFlagFwdDecl +// CHECK-SAME: identifier: "_ZTSN11SpecializedIiE6MemberE") + // Forward-declared member of a template. // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Member", // CHECK-SAME: flags: DIFlagFwdDecl