================
@@ -1332,6 +1332,54 @@ llvm::DIType *CGDebugInfo::CreateType(const 
TemplateSpecializationType *Ty,
   auto PP = getPrintingPolicy();
   Ty->getTemplateName().print(OS, PP, TemplateName::Qualified::None);
 
+  SourceLocation Loc = AliasDecl->getLocation();
+
+  if (CGM.getCodeGenOpts().DebugTemplateAlias) {
+    // TemplateSpecializationType doesn't know if its template args are
+    // being substituted into a parameter pack. We can find out if that's
+    // the case now by inspecting the TypeAliasTemplateDecl template
+    // parameters. Insert Ty's template args into SpecArgs, bundling args
+    // passed to a parameter pack into a TemplateArgument::Pack.
+    SmallVector<TemplateArgument> SpecArgs;
+    {
+      ArrayRef SubstArgs = Ty->template_arguments();
+      for (const NamedDecl *P : TD->getTemplateParameters()->asArray()) {
+        if (P->isParameterPack()) {
+          SpecArgs.push_back(TemplateArgument(SubstArgs));
+          break;
+        }
+        // Skip defaulted args.
+        if (SubstArgs.empty()) {
+          // If SubstArgs is now empty (we're taking from it each iteration) 
and
+          // this template parameter isn't a pack, then that should mean we're
+          // using default values for the remaining template parameters.
+          break;
----------------
OCHyams wrote:

>Sorry for diverting you down this path, maybe ignoring the default arguments 
>as you did in your first attempt is sufficient if this is just not feasible.

Not at all, I think it was worth exploring and I very much appreciate the 
detailed review and the help that's come with it.

I agree that ignoring default arguments might be the way forward then. It isn't 
a regression in terms of name reconstruction, since the existing typedef 
approach for template aliases omits defaulted arguments from the DW_AT_name 
anyway:

```
template <typename B = int, typename C = B>
using A = int;
A<> a;
```
`$ clang test.cpp -g -o - | llvm-dwarfdump -o -`
```
[...]
0x0000002e:   DW_TAG_typedef
                DW_AT_type      (0x00000036 "int")
                DW_AT_name      ("A<>")  <-- no defaulted arguments for 
template aliases :-(
                DW_AT_decl_file ("test.cpp")
                DW_AT_decl_line (41)
```

I have pushed that change (to omit defaulted arguments). Thanks for bearing 
with me on this one!

I've chatted to our debugger folks and they're ok with omitting defaulted args 
(though ideally this would be fixed in the future).

I think moving this discussion onto discourse might be useful - I'll look at 
doing that later in the week or next week.

https://github.com/llvm/llvm-project/pull/87623
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to