[clang] [llvm] [Clang] Emit DW_TAG_template_alias for template aliases (PR #87623)

David Blaikie via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 15 11:15:35 PDT 2024


dwblaikie wrote:

> Thanks @dwblaikie
> 
> > Bit unfortunate to store template parameters in different ways (in the extraData for the alias template, but in the templateParams for the composite types) - but I guess it'd be more invasive to try to represent alias templates as composite types?
> 
> I hadn't actually tried using DICompsiteType. I didn't choose DIDerivedType for any particularly principled reasons: typedefs use derived types which made it very easy to find places that needed updating, and an alias "felt" more like a derived type than composite type. Having looked only briefly, I don't _think_ it'd be any more invasive to use composite types instead (not 100% sure without diving in). I'm happy to give that a go if that is your preference?

Eh, I guess if we've already got DIGlobalVariable having template params, we aren't going to unify all 3 cases - not sure if unifying 2 out of three is particularly valuable, especially if it ends up with a different conflict (that alias templates look less like aliases & so need special casing in that direction)

But perhaps at least you could add named accessors to DIDerivedType for the template params, same as DIGlobalVariable/DICompositeType have?

(oh, and in case anyone hasn't mentioned it already - this would generally be committed in smaller pieces upstream - adding the LLVM functionality first, then adding clang patches that use that functionality)

> I've just found an input that causes an assertion failure in `CollectTemplateParams` with my implementation:
> 
> ```
> template<typename Y, typename Z>
> struct X {
>   Y m1;
>   Z m2;
> };
> 
> template<typename... Ts>
> using A = X<Ts...>;
> 
> A<int, int> a;
> ```
> 
> There's a mismatch between the template parameter list and template argument list sizes, created here:
> 
> ```
>   if (CGM.getCodeGenOpts().DebugTemplateAlias) {
>     TemplateArgs Args = {TD->getTemplateParameters(), Ty->template_arguments()}; // <--- here
> ```
> 
> I notice that we emit `DW_TAG_GNU_template_parameter_pack` for, e.g., variadic template struct instantiations. I've not figured out how to fix this just yet, but thought I'd bring it up in case there's something obvious.

yeah, probably worth checking the APIs that we use for building the template args for classes and variable templates, they probably have some handling for this - would be good to share/reuse that code, rather than duplicating it, once you find it

https://github.com/llvm/llvm-project/pull/87623


More information about the cfe-commits mailing list