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

Orlando Cazalet-Hyams via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 18 03:27:22 PDT 2024


================
@@ -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:

> Yup, would default values ever matter for name reconstruction?

I'd have thought not too, which is reflected in my initial approach of just leaving off defaulted args. However, it turns out our debugger displays defaulted values (this is intentional & desirable according to the team), and so does GDB.



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


More information about the cfe-commits mailing list