[PATCH] D145077: [clang][DebugInfo] Support DW_AT_LLVM_preferred_name attribute

Michael Buch via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 1 08:54:23 PST 2023


Michael137 created this revision.
Michael137 added reviewers: aprantl, dblaikie.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

With this patch, we now emit a `DW_AT_LLVM_preferred_name` for
the `[clang::preferred_name]]` attribute attached to a class template.

This is useful for consumers in case they want to display the
name in terms of the preferred name, e.g., LLDB's type-summaries.

For now this is behind an LLDB tuning.

E.g., for following code:

  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 {};

...the generated DWARF with this patch looks as follows:

  0x0000006b:   DW_TAG_structure_type
                  DW_AT_LLVM_preferred_name       (0x00000082)
                  DW_AT_name      ("Foo<int>")
  
  0x00000082:   DW_TAG_typedef
                 DW_AT_type      (0x0000006b "Foo<int>")
                 DW_AT_name      ("BarInt")
  
  0x0000008d:   DW_TAG_structure_type
                  DW_AT_LLVM_preferred_name       (0x000000ab)
                  DW_AT_name      ("Foo<double>")
  
  0x000000ab:   DW_TAG_typedef
                  DW_AT_type      (0x0000008d "Foo<double>")
                  DW_AT_name      ("BarDouble")


Repository:
  rG LLVM Github Monorepo

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145077.501538.patch
Type: text/x-patch
Size: 4316 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230301/333a5d80/attachment.bin>


More information about the cfe-commits mailing list