Michael137 updated this revision to Diff 501544.
Michael137 added a comment.

- clang-format


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,27 @@
+// RUN: %clang -target x86_64 -glldb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=LLDB
+// RUN: %clang -target x86_64 -ggdb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=GDB
+
+template<typename T>
+struct Foo;
+
+typedef Foo<int> BarInt;
+typedef Foo<double> BarDouble;
+
+template<typename T>
+struct [[clang::preferred_name(BarInt),
+         clang::preferred_name(BarDouble)]] Foo {};
+
+Foo<int> varInt;
+Foo<double> varDouble;
+
+// LLDB:      ![[FOO_DOUBLE:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo<double>"
+// GDB-NOT:   preferredName: ![[DOUBLE_PREF:[0-9]+]])
+// LLDB-SAME: preferredName: ![[DOUBLE_PREF:[0-9]+]])
+// LLDB:      !DIDerivedType(tag: DW_TAG_typedef, name: "BarDouble",
+// LLDB-SAME: baseType: ![[FOO_DOUBLE]])
+
+// LLDB:      ![[FOO_INT:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo<int>"
+// GDB-NOT:   preferredName: ![[INT_PREF:[0-9]+]])
+// LLDB-SAME: preferredName: ![[INT_PREF:[0-9]+]])
+// 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,27 @@
+// RUN: %clang -target x86_64 -glldb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=LLDB
+// RUN: %clang -target x86_64 -ggdb -S -emit-llvm -o - %s | FileCheck %s --check-prefix=GDB
+
+template<typename T>
+struct Foo;
+
+template<typename T>
+using Bar = Foo<T>;
+
+template<typename T>
+struct [[clang::preferred_name(Bar<T>)]] Foo {};
+
+Foo<int> varInt;
+Foo<Foo<int>> varFooInt;
+
+// LLDB:      ![[FOO_FOO_INT:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo<Foo<int> >"
+// GDB-NOT:   preferredName: ![[FOO_INT_PREF:[0-9]+]])
+// LLDB-SAME: preferredName: ![[FOO_INT_PREF:[0-9]+]])
+
+// LLDB:      ![[FOO_INT:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Foo<int>"
+// GDB-NOT:   preferredName: ![[INT_PREF:[0-9]+]])
+// LLDB-SAME: preferredName: ![[INT_PREF:[0-9]+]])
+
+// LLDB:      !DIDerivedType(tag: DW_TAG_typedef, name: "Bar<int>",
+// LLDB-SAME: baseType: ![[FOO_INT]])
+// LLDB:      !DIDerivedType(tag: DW_TAG_typedef, name: "Bar<Foo<int> >",
+// LLDB-SAME: baseType: ![[FOO_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

Reply via email to