This is an archive of the discontinued LLVM Phabricator instance.

[clang][DebugInfo] Support DW_AT_LLVM_preferred_name attribute
AcceptedPublic

Authored by Michael137 on Mar 1 2023, 8:54 AM.

Details

Reviewers
aprantl
dblaikie
Summary

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")

Diff Detail

Event Timeline

Michael137 created this revision.Mar 1 2023, 8:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2023, 8:54 AM
Michael137 requested review of this revision.Mar 1 2023, 8:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2023, 8:54 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
Michael137 updated this revision to Diff 501540.Mar 1 2023, 8:55 AM
  • Remove redundant TODO
Michael137 updated this revision to Diff 501544.Mar 1 2023, 9:10 AM
  • clang-format

Since the new attribute only gets attached to a structure definition, and the preferred_name attribute is currently only really used in a handful of places in libcxx, this practically doesn't affect debug-info size

aprantl accepted this revision.Mar 1 2023, 10:12 AM

I originally was hoping we wouldn't have to introduce a new attribute for this, but it looks like there are legitimate concerns about the alternatives, so in that sense this looks good!

This revision is now accepted and ready to land.Mar 1 2023, 10:12 AM
  • Add test case for multiple alias templates
  • Update test
Michael137 edited the summary of this revision. (Show Details)Mar 1 2023, 10:30 AM

I originally was hoping we wouldn't have to introduce a new attribute for this, but it looks like there are legitimate concerns about the alternatives, so in that sense this looks good!

Out of curiosity, what were the other existing attributes that were considered? (would be curious to have them written down here to explain/add strength to the motivation to add a new extension attribute)

I originally was hoping we wouldn't have to introduce a new attribute for this, but it looks like there are legitimate concerns about the alternatives, so in that sense this looks good!

Out of curiosity, what were the other existing attributes that were considered? (would be curious to have them written down here to explain/add strength to the motivation to add a new extension attribute)

Oh, I guess this discussion might go better in the llvm side that actually introduces the attribute D145076

Michael137 added a comment.EditedMar 10 2023, 2:00 PM

Making use of this in LLDB (see https://reviews.llvm.org/D145078) was a bit too finicky for my taste, so I prepared an alternative which doesn't require adding a new attribute (see https://reviews.llvm.org/D145803) and no LLDB changes. I *think* this is what @aprantl and @dblaikie had in mind couple of weeks back