[PATCH] D140423: [WIP][clang] Add PrintingPolicy callback for identifying default template arguments

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 13 11:44:54 PST 2023


aaron.ballman added a reviewer: erichkeane.
aaron.ballman added a subscriber: erichkeane.
aaron.ballman added a comment.

In D140423#4052271 <https://reviews.llvm.org/D140423#4052271>, @dblaikie wrote:

> In D140423#4051262 <https://reviews.llvm.org/D140423#4051262>, @aaron.ballman wrote:
>
>>> Add something like a bool IsDefaulted somewhere in Clang, e.g., in TemplateArgument and consult it from the TypePrinter. This would be much simpler but requires adding a field on one of the Clang types
>>
>> I think this might be worth exploring as a cleaner solution to the problem. `TemplateArgument` has a union of structures for the various kinds of template arguments it represents (https://github.com/llvm/llvm-project/blob/main/clang/include/clang/AST/TemplateBase.h#L140). All of the structures in that union start with an `unsigned Kind` field to discriminate between the members. There are only 8 kinds currently (https://github.com/llvm/llvm-project/blob/main/clang/include/clang/AST/TemplateBase.h#L63), so we could turn `Kind` into a bit-field and then steal a bit for `IsDefaulted` without increasing memory overhead. Do you think that's a reasonable approach to try instead?
>
> FWIW, I Think I discouraged @Michael137 from going down that direction since it felt weird to me to add that sort of thing to the Clang ASTs for an lldb-only use case, and a callback seemed more suitable. But this is hardly my wheelhouse - if you reckon that's the better direction, carry on, I expect @Michael137 will be on board with that.

Adding in @erichkeane as templates code owner in case he has opinions.

I agree it's a bit weird to modify the AST only for lldb only, but adding a callback to the printing policy is basically an lldb-only change as well (I don't imagine folks would use that callback all that often). So my thinking is that if we can encode the information in the AST for effectively zero cost, that helps every consumer of the AST (thinking about things like clang-tidy) and not just people printing. However, this is not a strongly held position, so if there's a preference for the current approach, it seems workable to me.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140423/new/

https://reviews.llvm.org/D140423



More information about the cfe-commits mailing list