@@ -1313,6 +1313,62 @@ llvm::DIType *CGDebugInfo::CreateType(const BlockPointerType *Ty,
1313
1313
return DBuilder.createPointerType (EltTy, Size);
1314
1314
}
1315
1315
1316
+ CGDebugInfo::TemplateArgs
1317
+ CGDebugInfo::GetTemplateArgs (const TemplateDecl *TD,
1318
+ const TemplateSpecializationType *Ty) const {
1319
+ assert (Ty->isTypeAlias ());
1320
+ // TemplateSpecializationType doesn't know if its template args are
1321
+ // being substituted into a parameter pack. We can find out if that's
1322
+ // the case now by inspecting the TypeAliasTemplateDecl template
1323
+ // parameters. Insert Ty's template args into SpecArgs, bundling args
1324
+ // passed to a parameter pack into a TemplateArgument::Pack. It also
1325
+ // doesn't know the value of any defaulted args, so collect those now
1326
+ // too.
1327
+ SmallVector<TemplateArgument> SpecArgs;
1328
+ ArrayRef SubstArgs = Ty->template_arguments ();
1329
+ for (const NamedDecl *Param : TD->getTemplateParameters ()->asArray ()) {
1330
+ // If Param is a parameter pack, pack the remaining arguments.
1331
+ if (Param->isParameterPack ()) {
1332
+ SpecArgs.push_back (TemplateArgument (SubstArgs));
1333
+ break ;
1334
+ }
1335
+
1336
+ // Take the next argument.
1337
+ if (!SubstArgs.empty ()) {
1338
+ SpecArgs.push_back (SubstArgs.front ());
1339
+ SubstArgs = SubstArgs.drop_front ();
1340
+ continue ;
1341
+ }
1342
+
1343
+ // If SubstArgs is now empty (we're taking from it each iteration) and
1344
+ // this template parameter isn't a pack, then that should mean we're
1345
+ // using default values for the remaining template parameters. Push the
1346
+ // default value for each parameter.
1347
+ if (auto *P = dyn_cast<TemplateTypeParmDecl>(Param)) {
1348
+ assert (P->hasDefaultArgument () &&
1349
+ " expected defaulted template type parameter" );
1350
+ SpecArgs.push_back (TemplateArgument (P->getDefaultArgument (),
1351
+ /* IsNullPtr=*/ false ,
1352
+ /* IsDefaulted=*/ true ));
1353
+ } else if (auto *P = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
1354
+ assert (P->hasDefaultArgument () &&
1355
+ " expected defaulted template non-type parameter" );
1356
+ SpecArgs.push_back (TemplateArgument (P->getDefaultArgument (),
1357
+ /* IsDefaulted=*/ true ));
1358
+ } else if (auto *P = dyn_cast<TemplateTemplateParmDecl>(Param)) {
1359
+ assert (P->hasDefaultArgument () &&
1360
+ " expected defaulted template template parameter" );
1361
+ SpecArgs.push_back (TemplateArgument (
1362
+ P->getDefaultArgument ().getArgument ().getAsTemplate (),
1363
+ /* IsDefaulted=*/ true ));
1364
+ } else {
1365
+ llvm_unreachable (" Unexpected template parameter kind" );
1366
+ break ;
1367
+ }
1368
+ }
1369
+ return {TD->getTemplateParameters (), SpecArgs};
1370
+ }
1371
+
1316
1372
llvm::DIType *CGDebugInfo::CreateType (const TemplateSpecializationType *Ty,
1317
1373
llvm::DIFile *Unit) {
1318
1374
assert (Ty->isTypeAlias ());
@@ -1335,58 +1391,7 @@ llvm::DIType *CGDebugInfo::CreateType(const TemplateSpecializationType *Ty,
1335
1391
SourceLocation Loc = AliasDecl->getLocation ();
1336
1392
1337
1393
if (CGM.getCodeGenOpts ().DebugTemplateAlias ) {
1338
- // TemplateSpecializationType doesn't know if its template args are
1339
- // being substituted into a parameter pack. We can find out if that's
1340
- // the case now by inspecting the TypeAliasTemplateDecl template
1341
- // parameters. Insert Ty's template args into SpecArgs, bundling args
1342
- // passed to a parameter pack into a TemplateArgument::Pack. It also
1343
- // doesn't know the value of any defaulted args, so collect those now
1344
- // too.
1345
- SmallVector<TemplateArgument> SpecArgs;
1346
- {
1347
- ArrayRef SubstArgs = Ty->template_arguments ();
1348
- for (const NamedDecl *Param : TD->getTemplateParameters ()->asArray ()) {
1349
- // If Param is a parameter pack, pack the remaining arguments.
1350
- if (Param->isParameterPack ()) {
1351
- SpecArgs.push_back (TemplateArgument (SubstArgs));
1352
- break ;
1353
- }
1354
-
1355
- // Take the next argument.
1356
- if (!SubstArgs.empty ()) {
1357
- SpecArgs.push_back (SubstArgs.front ());
1358
- SubstArgs = SubstArgs.drop_front ();
1359
- continue ;
1360
- }
1361
-
1362
- // If SubstArgs is now empty (we're taking from it each iteration) and
1363
- // this template parameter isn't a pack, then that should mean we're
1364
- // using default values for the remaining template parameters. Push the
1365
- // default value for each parameter.
1366
- if (auto *P = dyn_cast<TemplateTypeParmDecl>(Param)) {
1367
- assert (P->hasDefaultArgument () &&
1368
- " expected defaulted template type parameter" );
1369
- SpecArgs.push_back (TemplateArgument (P->getDefaultArgument (),
1370
- /* IsNullPtr=*/ false ,
1371
- /* IsDefaulted=*/ true ));
1372
- } else if (auto *P = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
1373
- assert (P->hasDefaultArgument () &&
1374
- " expected defaulted template non-type parameter" );
1375
- SpecArgs.push_back (TemplateArgument (P->getDefaultArgument (),
1376
- /* IsDefaulted=*/ true ));
1377
- } else if (auto *P = dyn_cast<TemplateTemplateParmDecl>(Param)) {
1378
- assert (P->hasDefaultArgument () &&
1379
- " expected defaulted template template parameter" );
1380
- SpecArgs.push_back (TemplateArgument (
1381
- P->getDefaultArgument ().getArgument ().getAsTemplate (),
1382
- /* IsDefaulted=*/ true ));
1383
- } else {
1384
- llvm_unreachable (" Unexpected template parameter kind" );
1385
- break ;
1386
- }
1387
- }
1388
- }
1389
- TemplateArgs Args = {TD->getTemplateParameters (), SpecArgs};
1394
+ TemplateArgs Args = GetTemplateArgs (TD, Ty);
1390
1395
1391
1396
// FIXME: Respect DebugTemplateNameKind::Mangled, e.g. by using GetName.
1392
1397
// Note we can't use GetName without additional work: TypeAliasTemplateDecl
0 commit comments