[PATCH] D25579: [codeview] emit debug info for indirect virtual base classes
This revision was automatically updated to reflect the committed changes. Closed by commit rL285132: [codeview] emit debug info for indirect virtual base classes (authored by inglorion). Changed prior to commit: https://reviews.llvm.org/D25579?vs=75381=75804#toc Repository: rL LLVM https://reviews.llvm.org/D25579 Files: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp cfe/trunk/lib/CodeGen/CGDebugInfo.h cfe/trunk/test/CodeGenCXX/debug-info-ms-vbase.cpp Index: cfe/trunk/test/CodeGenCXX/debug-info-ms-vbase.cpp === --- cfe/trunk/test/CodeGenCXX/debug-info-ms-vbase.cpp +++ cfe/trunk/test/CodeGenCXX/debug-info-ms-vbase.cpp @@ -24,6 +24,17 @@ // CHECK: ![[HasVirtualMethod_base]] = !DIDerivedType(tag: DW_TAG_inheritance, scope: ![[HasPrimaryBase]], baseType: ![[HasVirtualMethod]]) +// CHECK: ![[HasIndirectVirtualBase:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "HasIndirectVirtualBase" +// CHECK-SAME: elements: ![[elements:[0-9]+]] + +// CHECK: !DIDerivedType(tag: DW_TAG_inheritance, scope: ![[HasIndirectVirtualBase]], baseType: ![[HasPrimaryBase]] +// CHECK-NOT: DIFlagIndirectVirtualBase +// CHECK-SAME: ) + +// CHECK: !DIDerivedType(tag: DW_TAG_inheritance, scope: ![[HasIndirectVirtualBase]], baseType: ![[SecondaryVTable]] +// CHECK-SAME: flags: +// CHECK-SAME: DIFlagIndirectVirtualBase + // CHECK: ![[DynamicNoVFPtr:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "DynamicNoVFPtr", // CHECK-SAME: elements: ![[elements:[0-9]+]] @@ -52,3 +63,6 @@ HasPrimaryBase has_primary_base; +struct HasIndirectVirtualBase : public HasPrimaryBase {}; + +HasIndirectVirtualBase has_indirect_virtual_base; Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp === --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp @@ -13,9 +13,9 @@ #include "CGDebugInfo.h" #include "CGBlocks.h" -#include "CGRecordLayout.h" #include "CGCXXABI.h" #include "CGObjCRuntime.h" +#include "CGRecordLayout.h" #include "CodeGenFunction.h" #include "CodeGenModule.h" #include "clang/AST/ASTContext.h" @@ -31,6 +31,7 @@ #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/ModuleMap.h" #include "clang/Lex/PreprocessorOptions.h" +#include "llvm/ADT/DenseSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/IR/Constants.h" @@ -1380,13 +1381,33 @@ void CGDebugInfo::CollectCXXBases(const CXXRecordDecl *RD, llvm::DIFile *Unit, SmallVectorImpl , llvm::DIType *RecordTy) { - const ASTRecordLayout = CGM.getContext().getASTRecordLayout(RD); - for (const auto : RD->bases()) { -llvm::DINode::DIFlags BFlags = llvm::DINode::FlagZero; -uint64_t BaseOffset; + llvm::DenseSetSeenTypes; + CollectCXXBasesAux(RD, Unit, EltTys, RecordTy, RD->bases(), SeenTypes, + llvm::DINode::FlagZero); + + // If we are generating CodeView debug info, we also need to emit records for + // indirect virtual base classes. + if (CGM.getCodeGenOpts().EmitCodeView) { +CollectCXXBasesAux(RD, Unit, EltTys, RecordTy, RD->vbases(), SeenTypes, + llvm::DINode::FlagIndirectVirtualBase); + } +} +void CGDebugInfo::CollectCXXBasesAux( +const CXXRecordDecl *RD, llvm::DIFile *Unit, +SmallVectorImpl , llvm::DIType *RecordTy, +const CXXRecordDecl::base_class_const_range , +llvm::DenseSet , +llvm::DINode::DIFlags StartingFlags) { + const ASTRecordLayout = CGM.getContext().getASTRecordLayout(RD); + for (const auto : Bases) { const auto *Base = cast(BI.getType()->getAs()->getDecl()); +if (!SeenTypes.insert(Base).second) + continue; +auto *BaseTy = getOrCreateType(BI.getType(), Unit); +llvm::DINode::DIFlags BFlags = StartingFlags; +uint64_t BaseOffset; if (BI.isVirtual()) { if (CGM.getTarget().getCXXABI().isItaniumFamily()) { @@ -1401,15 +1422,15 @@ BaseOffset = 4 * CGM.getMicrosoftVTableContext().getVBTableIndex(RD, Base); } - BFlags = llvm::DINode::FlagVirtual; + BFlags |= llvm::DINode::FlagVirtual; } else BaseOffset = CGM.getContext().toBits(RL.getBaseClassOffset(Base)); // FIXME: Inconsistent units for BaseOffset. It is in bytes when // BI->isVirtual() and bits when not. BFlags |= getAccessFlag(BI.getAccessSpecifier(), RD); -llvm::DIType *DTy = DBuilder.createInheritance( -RecordTy, getOrCreateType(BI.getType(), Unit), BaseOffset, BFlags); +llvm::DIType *DTy = +DBuilder.createInheritance(RecordTy, BaseTy, BaseOffset, BFlags); EltTys.push_back(DTy); } } Index: cfe/trunk/lib/CodeGen/CGDebugInfo.h === --- cfe/trunk/lib/CodeGen/CGDebugInfo.h +++
[PATCH] D25579: [codeview] emit debug info for indirect virtual base classes
inglorion added a comment. We also need https://reviews.llvm.org/D25578 in before this can land. https://reviews.llvm.org/D25579 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D25579: [codeview] emit debug info for indirect virtual base classes
inglorion updated this revision to Diff 75381. inglorion added a comment. Use insert's return value to save a set lookup, and use CanonicalDeclPtr https://reviews.llvm.org/D25579 Files: lib/CodeGen/CGDebugInfo.cpp lib/CodeGen/CGDebugInfo.h test/CodeGenCXX/debug-info-ms-vbase.cpp Index: test/CodeGenCXX/debug-info-ms-vbase.cpp === --- test/CodeGenCXX/debug-info-ms-vbase.cpp +++ test/CodeGenCXX/debug-info-ms-vbase.cpp @@ -24,6 +24,17 @@ // CHECK: ![[HasVirtualMethod_base]] = !DIDerivedType(tag: DW_TAG_inheritance, scope: ![[HasPrimaryBase]], baseType: ![[HasVirtualMethod]]) +// CHECK: ![[HasIndirectVirtualBase:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "HasIndirectVirtualBase" +// CHECK-SAME: elements: ![[elements:[0-9]+]] + +// CHECK: !DIDerivedType(tag: DW_TAG_inheritance, scope: ![[HasIndirectVirtualBase]], baseType: ![[HasPrimaryBase]] +// CHECK-NOT: DIFlagIndirectVirtualBase +// CHECK-SAME: ) + +// CHECK: !DIDerivedType(tag: DW_TAG_inheritance, scope: ![[HasIndirectVirtualBase]], baseType: ![[SecondaryVTable]] +// CHECK-SAME: flags: +// CHECK-SAME: DIFlagIndirectVirtualBase + // CHECK: ![[DynamicNoVFPtr:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "DynamicNoVFPtr", // CHECK-SAME: elements: ![[elements:[0-9]+]] @@ -52,3 +63,6 @@ HasPrimaryBase has_primary_base; +struct HasIndirectVirtualBase : public HasPrimaryBase {}; + +HasIndirectVirtualBase has_indirect_virtual_base; Index: lib/CodeGen/CGDebugInfo.h === --- lib/CodeGen/CGDebugInfo.h +++ lib/CodeGen/CGDebugInfo.h @@ -15,12 +15,14 @@ #define LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H #include "CGBuilder.h" +#include "clang/AST/DeclCXX.h" #include "clang/AST/Expr.h" #include "clang/AST/ExternalASTSource.h" #include "clang/AST/Type.h" #include "clang/Basic/SourceLocation.h" #include "clang/Frontend/CodeGenOptions.h" #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/DenseSet.h" #include "llvm/ADT/Optional.h" #include "llvm/IR/DIBuilder.h" #include "llvm/IR/DebugInfo.h" @@ -32,7 +34,6 @@ } namespace clang { -class CXXMethodDecl; class ClassTemplateSpecializationDecl; class GlobalDecl; class ModuleMap; @@ -218,6 +219,15 @@ SmallVectorImpl , llvm::DIType *RecordTy); + /// Helper function for CollectCXXBases. + /// Adds debug info entries for types in Bases that are not in SeenTypes. + void CollectCXXBasesAux(const CXXRecordDecl *RD, llvm::DIFile *Unit, + SmallVectorImpl , + llvm::DIType *RecordTy, + const CXXRecordDecl::base_class_const_range , + llvm::DenseSet, + llvm::DINode::DIFlags StartingFlags); + /// A helper function to collect template parameters. llvm::DINodeArray CollectTemplateParams(const TemplateParameterList *TPList, ArrayRef TAList, Index: lib/CodeGen/CGDebugInfo.cpp === --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -13,9 +13,9 @@ #include "CGDebugInfo.h" #include "CGBlocks.h" -#include "CGRecordLayout.h" #include "CGCXXABI.h" #include "CGObjCRuntime.h" +#include "CGRecordLayout.h" #include "CodeGenFunction.h" #include "CodeGenModule.h" #include "clang/AST/ASTContext.h" @@ -31,6 +31,7 @@ #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/ModuleMap.h" #include "clang/Lex/PreprocessorOptions.h" +#include "llvm/ADT/DenseSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/IR/Constants.h" @@ -1380,13 +1381,33 @@ void CGDebugInfo::CollectCXXBases(const CXXRecordDecl *RD, llvm::DIFile *Unit, SmallVectorImpl , llvm::DIType *RecordTy) { - const ASTRecordLayout = CGM.getContext().getASTRecordLayout(RD); - for (const auto : RD->bases()) { -llvm::DINode::DIFlags BFlags = llvm::DINode::FlagZero; -uint64_t BaseOffset; + llvm::DenseSet SeenTypes; + CollectCXXBasesAux(RD, Unit, EltTys, RecordTy, RD->bases(), SeenTypes, + llvm::DINode::FlagZero); + + // If we are generating CodeView debug info, we also need to emit records for + // indirect virtual base classes. + if (CGM.getCodeGenOpts().EmitCodeView) { +CollectCXXBasesAux(RD, Unit, EltTys, RecordTy, RD->vbases(), SeenTypes, + llvm::DINode::FlagIndirectVirtualBase); + } +} +void CGDebugInfo::CollectCXXBasesAux( +const CXXRecordDecl *RD, llvm::DIFile *Unit, +SmallVectorImpl , llvm::DIType *RecordTy, +const CXXRecordDecl::base_class_const_range , +llvm::DenseSet , +llvm::DINode::DIFlags StartingFlags) { + const
[PATCH] D25579: [codeview] emit debug info for indirect virtual base classes
inglorion updated this revision to Diff 75367. inglorion added a comment. Updated to track the latest state of https://reviews.llvm.org/D25578 https://reviews.llvm.org/D25579 Files: lib/CodeGen/CGDebugInfo.cpp lib/CodeGen/CGDebugInfo.h test/CodeGenCXX/debug-info-ms-vbase.cpp Index: test/CodeGenCXX/debug-info-ms-vbase.cpp === --- test/CodeGenCXX/debug-info-ms-vbase.cpp +++ test/CodeGenCXX/debug-info-ms-vbase.cpp @@ -24,6 +24,17 @@ // CHECK: ![[HasVirtualMethod_base]] = !DIDerivedType(tag: DW_TAG_inheritance, scope: ![[HasPrimaryBase]], baseType: ![[HasVirtualMethod]]) +// CHECK: ![[HasIndirectVirtualBase:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "HasIndirectVirtualBase" +// CHECK-SAME: elements: ![[elements:[0-9]+]] + +// CHECK: !DIDerivedType(tag: DW_TAG_inheritance, scope: ![[HasIndirectVirtualBase]], baseType: ![[HasPrimaryBase]] +// CHECK-NOT: DIFlagIndirectVirtualBase +// CHECK-SAME: ) + +// CHECK: !DIDerivedType(tag: DW_TAG_inheritance, scope: ![[HasIndirectVirtualBase]], baseType: ![[SecondaryVTable]] +// CHECK-SAME: flags: +// CHECK-SAME: DIFlagIndirectVirtualBase + // CHECK: ![[DynamicNoVFPtr:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "DynamicNoVFPtr", // CHECK-SAME: elements: ![[elements:[0-9]+]] @@ -52,3 +63,6 @@ HasPrimaryBase has_primary_base; +struct HasIndirectVirtualBase : public HasPrimaryBase {}; + +HasIndirectVirtualBase has_indirect_virtual_base; Index: lib/CodeGen/CGDebugInfo.h === --- lib/CodeGen/CGDebugInfo.h +++ lib/CodeGen/CGDebugInfo.h @@ -15,12 +15,14 @@ #define LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H #include "CGBuilder.h" +#include "clang/AST/DeclCXX.h" #include "clang/AST/Expr.h" #include "clang/AST/ExternalASTSource.h" #include "clang/AST/Type.h" #include "clang/Basic/SourceLocation.h" #include "clang/Frontend/CodeGenOptions.h" #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/DenseSet.h" #include "llvm/ADT/Optional.h" #include "llvm/IR/DIBuilder.h" #include "llvm/IR/DebugInfo.h" @@ -32,7 +34,6 @@ } namespace clang { -class CXXMethodDecl; class ClassTemplateSpecializationDecl; class GlobalDecl; class ModuleMap; @@ -218,6 +219,15 @@ SmallVectorImpl , llvm::DIType *RecordTy); + /// Helper function for CollectCXXBases. + /// Adds debug info entries for types in Bases that are not in SeenTypes. + void CollectCXXBasesAux(const CXXRecordDecl *RD, llvm::DIFile *Unit, + SmallVectorImpl , + llvm::DIType *RecordTy, + const CXXRecordDecl::base_class_const_range , + llvm::DenseSet , + llvm::DINode::DIFlags StartingFlags); + /// A helper function to collect template parameters. llvm::DINodeArray CollectTemplateParams(const TemplateParameterList *TPList, ArrayRef TAList, Index: lib/CodeGen/CGDebugInfo.cpp === --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -13,9 +13,9 @@ #include "CGDebugInfo.h" #include "CGBlocks.h" -#include "CGRecordLayout.h" #include "CGCXXABI.h" #include "CGObjCRuntime.h" +#include "CGRecordLayout.h" #include "CodeGenFunction.h" #include "CodeGenModule.h" #include "clang/AST/ASTContext.h" @@ -31,6 +31,7 @@ #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/ModuleMap.h" #include "clang/Lex/PreprocessorOptions.h" +#include "llvm/ADT/DenseSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/IR/Constants.h" @@ -1380,13 +1381,35 @@ void CGDebugInfo::CollectCXXBases(const CXXRecordDecl *RD, llvm::DIFile *Unit, SmallVectorImpl , llvm::DIType *RecordTy) { - const ASTRecordLayout = CGM.getContext().getASTRecordLayout(RD); - for (const auto : RD->bases()) { -llvm::DINode::DIFlags BFlags = llvm::DINode::FlagZero; -uint64_t BaseOffset; + llvm::DenseSet SeenTypes; + CollectCXXBasesAux(RD, Unit, EltTys, RecordTy, RD->bases(), SeenTypes, + llvm::DINode::FlagZero); + + // If we are generating CodeView debug info, we also need to emit records for + // indirect virtual base classes. + if (CGM.getCodeGenOpts().EmitCodeView) { +CollectCXXBasesAux(RD, Unit, EltTys, RecordTy, RD->vbases(), SeenTypes, + llvm::DINode::FlagIndirectVirtualBase); + } +} +void CGDebugInfo::CollectCXXBasesAux( +const CXXRecordDecl *RD, llvm::DIFile *Unit, +SmallVectorImpl , llvm::DIType *RecordTy, +const CXXRecordDecl::base_class_const_range , +llvm::DenseSet , +llvm::DINode::DIFlags StartingFlags) { + const ASTRecordLayout = CGM.getContext().getASTRecordLayout(RD);
[PATCH] D25579: [codeview] emit debug info for indirect virtual base classes
rnk accepted this revision. rnk added a comment. This revision is now accepted and ready to land. Thanks, looks good with some nits Comment at: lib/CodeGen/CGDebugInfo.cpp:1397 const auto *Base = cast(BI.getType()->getAs()->getDecl()); rnk wrote: > You should be able to use this as the key into SeenTypes. You also want to do > `Base = Base->getCanonicalDecl()`, though, so that we don't end up with > pointers to different redeclarations of the same record. I don't think I can > construct a case where this would matter, but it's probably still worth it. :) So, the playing field shifted. Justin Lebar recently added the CanonicalDeclPtr template, which does the getCanonicalDecl dance for you. Probably best to use that. :) Comment at: lib/CodeGen/CGDebugInfo.cpp:1393-1395 +if (is_contained(SeenTypes, CanonicalBase)) + continue; +SeenTypes.insert(CanonicalBase); Now that we've figured out the best way to test set membership, I've realized we can save a hash lookup like this: if (SeenTypes.insert(CanonicalBase).second) continue; https://reviews.llvm.org/D25579 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D25579: [codeview] emit debug info for indirect virtual base classes
inglorion updated this revision to Diff 74734. inglorion added a comment. - Removed unused header. https://reviews.llvm.org/D25579 Files: lib/CodeGen/CGDebugInfo.cpp lib/CodeGen/CGDebugInfo.h test/CodeGenCXX/debug-info-ms-vbase.cpp Index: test/CodeGenCXX/debug-info-ms-vbase.cpp === --- test/CodeGenCXX/debug-info-ms-vbase.cpp +++ test/CodeGenCXX/debug-info-ms-vbase.cpp @@ -24,6 +24,18 @@ // CHECK: ![[HasVirtualMethod_base]] = !DIDerivedType(tag: DW_TAG_inheritance, scope: ![[HasPrimaryBase]], baseType: ![[HasVirtualMethod]]) +// CHECK: ![[HasIndirectVirtualBase:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "HasIndirectVirtualBase" +// CHECK-SAME: elements: ![[elements:[0-9]+]] + +// CHECK: !DIDerivedType(tag: DW_TAG_inheritance, scope: ![[HasIndirectVirtualBase]], baseType: ![[HasPrimaryBase]] +// CHECK-NOT: DIFlagIndirect +// CHECK-SAME: ) + +// CHECK: !DIDerivedType(tag: DW_TAG_inheritance, scope: ![[HasIndirectVirtualBase]], baseType: ![[SecondaryVTable]] +// CHECK-SAME: flags: +// CHECK-SAME: DIFlagVirtual +// CHECK-SAME: DIFlagIndirect + // CHECK: ![[DynamicNoVFPtr:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "DynamicNoVFPtr", // CHECK-SAME: elements: ![[elements:[0-9]+]] @@ -52,3 +64,6 @@ HasPrimaryBase has_primary_base; +struct HasIndirectVirtualBase : public HasPrimaryBase {}; + +HasIndirectVirtualBase has_indirect_virtual_base; Index: lib/CodeGen/CGDebugInfo.h === --- lib/CodeGen/CGDebugInfo.h +++ lib/CodeGen/CGDebugInfo.h @@ -15,12 +15,14 @@ #define LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H #include "CGBuilder.h" +#include "clang/AST/DeclCXX.h" #include "clang/AST/Expr.h" #include "clang/AST/ExternalASTSource.h" #include "clang/AST/Type.h" #include "clang/Basic/SourceLocation.h" #include "clang/Frontend/CodeGenOptions.h" #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/DenseSet.h" #include "llvm/ADT/Optional.h" #include "llvm/IR/DIBuilder.h" #include "llvm/IR/DebugInfo.h" @@ -32,7 +34,6 @@ } namespace clang { -class CXXMethodDecl; class ClassTemplateSpecializationDecl; class GlobalDecl; class ModuleMap; @@ -218,6 +219,15 @@ SmallVectorImpl , llvm::DIType *RecordTy); + /// Helper function for CollectCXXBases. + /// Adds debug info entries for types in Bases that are not in SeenTypes. + void CollectCXXBasesAux(const CXXRecordDecl *RD, llvm::DIFile *Unit, + SmallVectorImpl , + llvm::DIType *RecordTy, + const CXXRecordDecl::base_class_const_range , + llvm::DenseSet , + llvm::DINode::DIFlags StartingFlags); + /// A helper function to collect template parameters. llvm::DINodeArray CollectTemplateParams(const TemplateParameterList *TPList, ArrayRef TAList, Index: lib/CodeGen/CGDebugInfo.cpp === --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -13,9 +13,9 @@ #include "CGDebugInfo.h" #include "CGBlocks.h" -#include "CGRecordLayout.h" #include "CGCXXABI.h" #include "CGObjCRuntime.h" +#include "CGRecordLayout.h" #include "CodeGenFunction.h" #include "CodeGenModule.h" #include "clang/AST/ASTContext.h" @@ -31,6 +31,7 @@ #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/ModuleMap.h" #include "clang/Lex/PreprocessorOptions.h" +#include "llvm/ADT/DenseSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/IR/Constants.h" @@ -1366,13 +1367,35 @@ void CGDebugInfo::CollectCXXBases(const CXXRecordDecl *RD, llvm::DIFile *Unit, SmallVectorImpl , llvm::DIType *RecordTy) { - const ASTRecordLayout = CGM.getContext().getASTRecordLayout(RD); - for (const auto : RD->bases()) { -llvm::DINode::DIFlags BFlags = llvm::DINode::FlagZero; -uint64_t BaseOffset; + llvm::DenseSet SeenTypes; + CollectCXXBasesAux(RD, Unit, EltTys, RecordTy, RD->bases(), SeenTypes, + llvm::DINode::FlagZero); + + // If we are generating CodeView debug info, we also need to emit records for + // indirect virtual base classes. + if (CGM.getCodeGenOpts().EmitCodeView) { +CollectCXXBasesAux(RD, Unit, EltTys, RecordTy, RD->vbases(), SeenTypes, + llvm::DINode::FlagIndirect | llvm::DINode::FlagVirtual); + } +} +void CGDebugInfo::CollectCXXBasesAux( +const CXXRecordDecl *RD, llvm::DIFile *Unit, +SmallVectorImpl , llvm::DIType *RecordTy, +const CXXRecordDecl::base_class_const_range , +llvm::DenseSet , +llvm::DINode::DIFlags StartingFlags) { + const ASTRecordLayout = CGM.getContext().getASTRecordLayout(RD); + for (const auto
[PATCH] D25579: [codeview] emit debug info for indirect virtual base classes
inglorion updated this revision to Diff 74733. inglorion added a comment. @rnk's comments (thanks!) - Converted SeenTypes to a DenseSet. - Switched to getCodeGenOpts().EmitCodeView to check if we should emit the extra records. - Switched to using SeenTypes.count(...) != 0 to check if we've seen a type. https://reviews.llvm.org/D25579 Files: lib/CodeGen/CGDebugInfo.cpp lib/CodeGen/CGDebugInfo.h test/CodeGenCXX/debug-info-ms-vbase.cpp Index: test/CodeGenCXX/debug-info-ms-vbase.cpp === --- test/CodeGenCXX/debug-info-ms-vbase.cpp +++ test/CodeGenCXX/debug-info-ms-vbase.cpp @@ -24,6 +24,18 @@ // CHECK: ![[HasVirtualMethod_base]] = !DIDerivedType(tag: DW_TAG_inheritance, scope: ![[HasPrimaryBase]], baseType: ![[HasVirtualMethod]]) +// CHECK: ![[HasIndirectVirtualBase:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "HasIndirectVirtualBase" +// CHECK-SAME: elements: ![[elements:[0-9]+]] + +// CHECK: !DIDerivedType(tag: DW_TAG_inheritance, scope: ![[HasIndirectVirtualBase]], baseType: ![[HasPrimaryBase]] +// CHECK-NOT: DIFlagIndirect +// CHECK-SAME: ) + +// CHECK: !DIDerivedType(tag: DW_TAG_inheritance, scope: ![[HasIndirectVirtualBase]], baseType: ![[SecondaryVTable]] +// CHECK-SAME: flags: +// CHECK-SAME: DIFlagVirtual +// CHECK-SAME: DIFlagIndirect + // CHECK: ![[DynamicNoVFPtr:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "DynamicNoVFPtr", // CHECK-SAME: elements: ![[elements:[0-9]+]] @@ -52,3 +64,6 @@ HasPrimaryBase has_primary_base; +struct HasIndirectVirtualBase : public HasPrimaryBase {}; + +HasIndirectVirtualBase has_indirect_virtual_base; Index: lib/CodeGen/CGDebugInfo.h === --- lib/CodeGen/CGDebugInfo.h +++ lib/CodeGen/CGDebugInfo.h @@ -15,12 +15,14 @@ #define LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H #include "CGBuilder.h" +#include "clang/AST/DeclCXX.h" #include "clang/AST/Expr.h" #include "clang/AST/ExternalASTSource.h" #include "clang/AST/Type.h" #include "clang/Basic/SourceLocation.h" #include "clang/Frontend/CodeGenOptions.h" #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/DenseSet.h" #include "llvm/ADT/Optional.h" #include "llvm/IR/DIBuilder.h" #include "llvm/IR/DebugInfo.h" @@ -32,7 +34,6 @@ } namespace clang { -class CXXMethodDecl; class ClassTemplateSpecializationDecl; class GlobalDecl; class ModuleMap; @@ -218,6 +219,15 @@ SmallVectorImpl , llvm::DIType *RecordTy); + /// Helper function for CollectCXXBases. + /// Adds debug info entries for types in Bases that are not in SeenTypes. + void CollectCXXBasesAux(const CXXRecordDecl *RD, llvm::DIFile *Unit, + SmallVectorImpl , + llvm::DIType *RecordTy, + const CXXRecordDecl::base_class_const_range , + llvm::DenseSet , + llvm::DINode::DIFlags StartingFlags); + /// A helper function to collect template parameters. llvm::DINodeArray CollectTemplateParams(const TemplateParameterList *TPList, ArrayRef TAList, Index: lib/CodeGen/CGDebugInfo.cpp === --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -13,9 +13,9 @@ #include "CGDebugInfo.h" #include "CGBlocks.h" -#include "CGRecordLayout.h" #include "CGCXXABI.h" #include "CGObjCRuntime.h" +#include "CGRecordLayout.h" #include "CodeGenFunction.h" #include "CodeGenModule.h" #include "clang/AST/ASTContext.h" @@ -31,7 +31,9 @@ #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/ModuleMap.h" #include "clang/Lex/PreprocessorOptions.h" +#include "llvm/ADT/DenseSet.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DataLayout.h" @@ -1366,13 +1368,35 @@ void CGDebugInfo::CollectCXXBases(const CXXRecordDecl *RD, llvm::DIFile *Unit, SmallVectorImpl , llvm::DIType *RecordTy) { - const ASTRecordLayout = CGM.getContext().getASTRecordLayout(RD); - for (const auto : RD->bases()) { -llvm::DINode::DIFlags BFlags = llvm::DINode::FlagZero; -uint64_t BaseOffset; + llvm::DenseSet SeenTypes; + CollectCXXBasesAux(RD, Unit, EltTys, RecordTy, RD->bases(), SeenTypes, + llvm::DINode::FlagZero); + + // If we are generating CodeView debug info, we also need to emit records for + // indirect virtual base classes. + if (CGM.getCodeGenOpts().EmitCodeView) { +CollectCXXBasesAux(RD, Unit, EltTys, RecordTy, RD->vbases(), SeenTypes, + llvm::DINode::FlagIndirect | llvm::DINode::FlagVirtual); + } +} +void CGDebugInfo::CollectCXXBasesAux( +const CXXRecordDecl
[PATCH] D25579: [codeview] emit debug info for indirect virtual base classes
majnemer added inline comments. Comment at: lib/CodeGen/CGDebugInfo.cpp:1392 +auto *BaseTy = getOrCreateType(BI.getType(), Unit); +if (SeenTypes.find(BaseTy) != SeenTypes.end()) + continue; ruiu wrote: > zturner wrote: > > rnk wrote: > > > IMO `SeenTypes.count(...)` would be more idiomatic. > > What a silly function. I wonder why it isn't called `contains()` and > > return a `bool`. > It's probably because std::set doesn't provide `contains()` but `count()` too. You can use `is_contained` from STLExtras.h, it should be maximally idiomatic :) https://reviews.llvm.org/D25579 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D25579: [codeview] emit debug info for indirect virtual base classes
ruiu added inline comments. Comment at: lib/CodeGen/CGDebugInfo.cpp:1392 +auto *BaseTy = getOrCreateType(BI.getType(), Unit); +if (SeenTypes.find(BaseTy) != SeenTypes.end()) + continue; zturner wrote: > rnk wrote: > > IMO `SeenTypes.count(...)` would be more idiomatic. > What a silly function. I wonder why it isn't called `contains()` and return > a `bool`. It's probably because std::set doesn't provide `contains()` but `count()` too. https://reviews.llvm.org/D25579 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits