Michael137 updated this revision to Diff 501569. Michael137 added a comment.
- Update test Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D145077/new/ https://reviews.llvm.org/D145077 Files: clang/lib/CodeGen/CGDebugInfo.cpp clang/lib/CodeGen/CGDebugInfo.h clang/test/CodeGen/attr-preferred_name-alias-template.cpp clang/test/CodeGen/attr-preferred_name-typedef.cpp
Index: clang/test/CodeGen/attr-preferred_name-typedef.cpp =================================================================== --- /dev/null +++ clang/test/CodeGen/attr-preferred_name-typedef.cpp @@ -0,0 +1,38 @@ +// RUN: %clang -target x86_64 -glldb -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=LLDB,COMMON +// RUN: %clang -target x86_64 -ggdb -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=GDB,COMMON + +template<typename T> +struct Foo; + +typedef Foo<int> BarInt; +typedef Foo<double> BarDouble; +typedef Foo<char> BarChar; + +template<typename T> +struct [[clang::preferred_name(BarInt), + clang::preferred_name(BarDouble)]] Foo {}; + +Foo<int> varInt; +Foo<double> varDouble; +Foo<char> varChar; + +// COMMON: ![[FOO_DOUBLE:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo<double>" +// GDB-NOT: preferredName: [[#]] +// LLDB-SAME: preferredName: ![[DOUBLE_PREF:[0-9]+]]) +// COMMON: ) + +// LLDB: !DIDerivedType(tag: DW_TAG_typedef, name: "BarDouble", +// LLDB-SAME: baseType: ![[FOO_DOUBLE]]) + +// COMMON: !DICompositeType(tag: DW_TAG_structure_type, name: "Foo<char>" +// GDB-NOT: preferredName: [[#]] +// LLDB-NOT: preferredName: [[#]] +// COMMON: ) + +// COMMON: ![[FOO_INT:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo<int>" +// GDB-NOT: preferredName: [[#]] +// LLDB-SAME: preferredName: ![[INT_PREF:[0-9]+]]) +// COMMON: ) + +// LLDB: !DIDerivedType(tag: DW_TAG_typedef, name: "BarInt", +// LLDB-SAME: baseType: ![[FOO_INT]]) Index: clang/test/CodeGen/attr-preferred_name-alias-template.cpp =================================================================== --- /dev/null +++ clang/test/CodeGen/attr-preferred_name-alias-template.cpp @@ -0,0 +1,37 @@ +// RUN: %clang -target x86_64 -glldb -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=LLDB,COMMON +// RUN: %clang -target x86_64 -ggdb -S -emit-llvm -o - %s | FileCheck %s --check-prefixes=GDB,COMMON + +template<typename T> +struct Foo; + +template<typename T> +using Bar = Foo<T>; + +template<typename T> +struct [[clang::preferred_name(Bar<int>), + clang::preferred_name(Bar<double>)]] Foo {}; + +Foo<int> varInt; +Foo<double> varDouble; +Foo<char> varChar; + +// COMMON: ![[FOO_DOUBLE:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo<double>" +// GDB-NOT: preferredName: [[#]] +// LLDB-SAME: preferredName: ![[DOUBLE_PREF:[0-9]+]] +// COMMON-SAME: ) + +// LLDB: ![[DOUBLE_PREF]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Bar<double>", +// LLDB-SAME: baseType: ![[FOO_DOUBLE]] + +// COMMON: !DICompositeType(tag: DW_TAG_structure_type, name: "Foo<char>" +// GDB-NOT: preferredName: [[#]] +// LLDB-NOT: preferredName: [[#]] +// COMMON-SAME: ) + +// COMMON: ![[FOO_INT:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo<int>" +// GDB-NOT: preferredName: [[#]] +// LLDB-SAME: preferredName: ![[INT_PREF:[0-9]+]] +// COMMON-SAME: ) + +// LLDB: ![[INT_PREF]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Bar<int>", +// LLDB-SAME: baseType: ![[FOO_INT]] Index: clang/lib/CodeGen/CGDebugInfo.h =================================================================== --- clang/lib/CodeGen/CGDebugInfo.h +++ clang/lib/CodeGen/CGDebugInfo.h @@ -267,6 +267,12 @@ SmallVectorImpl<llvm::Metadata *> &EltTys, llvm::DIType *RecordTy); + /// Helper class that retrieves returns llvm::DIType the that + /// PreferredNameAttr attribute on \ref RD refers to. If no such + /// attribute exists, returns nullptr. + llvm::DIType *GetPreferredNameType(const CXXRecordDecl *RD, + llvm::DIFile *Unit); + /// Helper function for CollectCXXBases. /// Adds debug info entries for types in Bases that are not in SeenTypes. void CollectCXXBasesAux( Index: clang/lib/CodeGen/CGDebugInfo.cpp =================================================================== --- clang/lib/CodeGen/CGDebugInfo.cpp +++ clang/lib/CodeGen/CGDebugInfo.cpp @@ -2576,6 +2576,18 @@ return CreateTypeDefinition(Ty); } +llvm::DIType *CGDebugInfo::GetPreferredNameType(const CXXRecordDecl *RD, + llvm::DIFile *Unit) { + if (!RD) + return nullptr; + + auto const *PNA = RD->getAttr<PreferredNameAttr>(); + if (!PNA) + return nullptr; + + return getOrCreateType(PNA->getTypedefType(), Unit); +} + llvm::DIType *CGDebugInfo::CreateTypeDefinition(const RecordType *Ty) { RecordDecl *RD = Ty->getDecl(); @@ -2630,6 +2642,9 @@ FwdDecl = llvm::MDNode::replaceWithPermanent(llvm::TempDICompositeType(FwdDecl)); + if (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB) + FwdDecl->replacePreferredName(GetPreferredNameType(CXXDecl, DefUnit)); + RegionMap[Ty->getDecl()].reset(FwdDecl); return FwdDecl; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits