This is an archive of the discontinued LLVM Phabricator instance.

[clang][DebugInfo] Don't canonicalize names in template argument list for alias templates
ClosedPublic

Authored by Michael137 on Jan 20 2023, 6:22 PM.

Details

Summary

Summary

This patch customizes the CGDebugInfo printing policy to stop canonicalizing
the template arugment list in DW_AT_name for alias templates. The motivation for
this is that we want to be able to use the TypePrinters support for
omitting defaulted template arguments when emitting DW_AT_name.

For reference, GCC currently completely omits the template arguments
when emitting alias template DIEs.

Testing

  • Added unit-test

Diff Detail

Event Timeline

Michael137 created this revision.Jan 20 2023, 6:22 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 20 2023, 6:22 PM
Michael137 requested review of this revision.Jan 20 2023, 6:22 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 20 2023, 6:22 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
  • Update commit message
Michael137 added a comment.EditedJan 20 2023, 6:25 PM

@dblaikie suggested that the best way to go about the recurring "how do we print template names" question is to turn -gsimple-template-names on by default. For alias templates this means we would have to attach template parameters to their DIEs too.

So @Michael137 and I talked about this offline, and a few extra details:

  • Generally it's important that types have identical names. Templates try to do this, but get it wrong in a bunch of ways (& certainly between GCC and Clang we get it different in a bunch of ways too) which are all problematic/could cause a debugger to not correctly identify two types in distinct CUs as being actually the same type.
    • That's why we usually use the full name of a template, to ensure it's identical between instantiations in different CUs
  • Because compilers don't all produce character-for-character identical names, debuggers mostly have to throw away the "<.*>" and recanonicalize from the DW_TAG_template_*_parameters anyway..
  • But none of that matters, because alias templates aren't strong aliases - they aren't part of the type system, they're just a name that code can use
  • As mentioned, GCC currently only uses the base name, no template parameters - which isn't super helpful (since you'd then end up with a bunch of different alias template instantiations all with the same name).
  • Clang produces the alias template with the template parameters in the DW_AT_name, but without any DW_TAG_template_*_parameter DIEs, which means we can't apply Simple Template Names here, currently - though might be a nice thing to do at somepoint.

But for now, since the name doesn't actually have to be deconstruct/canonicalize the template parameters - we can just pick whatever name is nice for the user, really.

So, I think this is an OK change to make for now - though probably the nicer thing, long-term, would be to add the template parameter DIEs, and under -gsimple-template-names remove the template parameters from the DW_AT_name (& maybe eventually turn that on by default/migrate to -gsimple-template-names) but for now/when using non`-gsimple-template-names`, this seems OK, if a bit weird/inconsistent, but for good reasons because the alias template isn't part of the type system. (thanks for including the FIXME there)

This revision is now accepted and ready to land.Jan 22 2023, 9:42 PM

So @Michael137 and I talked about this offline, and a few extra details:

  • Generally it's important that types have identical names. Templates try to do this, but get it wrong in a bunch of ways (& certainly between GCC and Clang we get it different in a bunch of ways too) which are all problematic/could cause a debugger to not correctly identify two types in distinct CUs as being actually the same type.
    • That's why we usually use the full name of a template, to ensure it's identical between instantiations in different CUs
  • Because compilers don't all produce character-for-character identical names, debuggers mostly have to throw away the "<.*>" and recanonicalize from the DW_TAG_template_*_parameters anyway..
  • But none of that matters, because alias templates aren't strong aliases - they aren't part of the type system, they're just a name that code can use
  • As mentioned, GCC currently only uses the base name, no template parameters - which isn't super helpful (since you'd then end up with a bunch of different alias template instantiations all with the same name).
  • Clang produces the alias template with the template parameters in the DW_AT_name, but without any DW_TAG_template_*_parameter DIEs, which means we can't apply Simple Template Names here, currently - though might be a nice thing to do at somepoint.

But for now, since the name doesn't actually have to be deconstruct/canonicalize the template parameters - we can just pick whatever name is nice for the user, really.

So, I think this is an OK change to make for now - though probably the nicer thing, long-term, would be to add the template parameter DIEs, and under -gsimple-template-names remove the template parameters from the DW_AT_name (& maybe eventually turn that on by default/migrate to -gsimple-template-names) but for now/when using non`-gsimple-template-names`, this seems OK, if a bit weird/inconsistent, but for good reasons because the alias template isn't part of the type system. (thanks for including the FIXME there)

Thanks for the extensive summary!

This revision was landed with ongoing or failed builds.Jan 23 2023, 1:43 AM
This revision was automatically updated to reflect the committed changes.