amccarth created this revision. amccarth added reviewers: rnk, dblaikie. amccarth added a subscriber: cfe-commits.
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. This is essentially my earlier patch with a switch to apply it only when generating CodeView. https://reviews.llvm.org/D22577 Files: lib/CodeGen/CGDebugInfo.cpp lib/CodeGen/CGDebugInfo.h test/CodeGenCXX/debug-info-dup-fwd-decl.cpp test/CodeGenCXX/debug-info-ms-abi.cpp test/Modules/ModuleDebugInfo.cpp
Index: test/Modules/ModuleDebugInfo.cpp =================================================================== --- test/Modules/ModuleDebugInfo.cpp +++ test/Modules/ModuleDebugInfo.cpp @@ -121,15 +121,19 @@ // CHECK-SAME: flags: DIFlagFwdDecl, // CHECK-SAME: identifier: "_ZTS9Template1IPvE") -// Explicit instatiation. +// Explicit instantiation. // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "Template1<int>", // CHECK-SAME: templateParams: // CHECK-SAME: identifier: "_ZTS9Template1IiE") // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "FwdDeclTemplate<int>", // 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 Index: test/CodeGenCXX/debug-info-ms-abi.cpp =================================================================== --- test/CodeGenCXX/debug-info-ms-abi.cpp +++ 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. @@ -14,6 +14,9 @@ // CHECK: ![[Foo:[^ ]*]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo", // CHECK-SAME: identifier: ".?AUFoo@@" +// CHECK: distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Nested", +// CHECK-SAME: identifier: ".?AUNested@Foo@@" + // CHECK: !DISubprogram(name: "f", // CHECK-SAME: containingType: ![[Foo]], virtuality: DW_VIRTUALITY_virtual, virtualIndex: 0, // CHECK-SAME: flags: DIFlagPrototyped | DIFlagIntroducedVirtual, @@ -25,6 +28,3 @@ // CHECK: !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@@" Index: test/CodeGenCXX/debug-info-dup-fwd-decl.cpp =================================================================== --- test/CodeGenCXX/debug-info-dup-fwd-decl.cpp +++ test/CodeGenCXX/debug-info-dup-fwd-decl.cpp @@ -19,6 +19,6 @@ 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" Index: lib/CodeGen/CGDebugInfo.h =================================================================== --- lib/CodeGen/CGDebugInfo.h +++ lib/CodeGen/CGDebugInfo.h @@ -254,6 +254,8 @@ llvm::DIFile *F, SmallVectorImpl<llvm::Metadata *> &E, llvm::DIType *RecordTy, const RecordDecl *RD); + void CollectRecordNestedRecord(const RecordDecl *RD, + SmallVectorImpl<llvm::Metadata *> &E); void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile *F, SmallVectorImpl<llvm::Metadata *> &E, llvm::DICompositeType *RecordTy); Index: lib/CodeGen/CGDebugInfo.cpp =================================================================== --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -1090,6 +1090,13 @@ elements.push_back(FieldType); } +void CGDebugInfo::CollectRecordNestedRecord( + const RecordDecl *RD, SmallVectorImpl<llvm::Metadata *> &elements) { + QualType Ty = CGM.getContext().getTypeDeclType(RD); + llvm::DIType *nestedType = getOrCreateType(Ty, getOrCreateMainFile()); + elements.push_back(nestedType); +} + void CGDebugInfo::CollectRecordFields( const RecordDecl *record, llvm::DIFile *tunit, SmallVectorImpl<llvm::Metadata *> &elements, @@ -1101,6 +1108,10 @@ 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 +1137,10 @@ // Bump field number for next field. ++fieldNo; - } + } else if (const auto *nestedRec = dyn_cast<CXXRecordDecl>(I)) + if (IncludeNestedRecords && !nestedRec->isImplicit() && + nestedRec->getDeclContext() == record) + CollectRecordNestedRecord(nestedRec, elements); } } @@ -3620,8 +3634,8 @@ 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<Decl>(UD.getDeclContext())), getOrCreateNameSpace(NSDecl),
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits