Skip to content

Commit 0952cf9

Browse files
committed
ignore defaulted args -- see inline discussion
1 parent 7795894 commit 0952cf9

File tree

2 files changed

+23
-35
lines changed

2 files changed

+23
-35
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,38 +1332,21 @@ GetTemplateArgs(const TemplateDecl *TD, const TemplateSpecializationType *Ty) {
13321332
break;
13331333
}
13341334

1335-
// Take the next argument.
1336-
if (!SubstArgs.empty()) {
1337-
SpecArgs.push_back(SubstArgs.front());
1338-
SubstArgs = SubstArgs.drop_front();
1339-
continue;
1340-
}
1341-
1342-
// If SubstArgs is now empty (we're taking from it each iteration) and
1343-
// this template parameter isn't a pack, then that should mean we're
1344-
// using default values for the remaining template parameters. Push the
1345-
// default value for each parameter.
1346-
if (auto *P = dyn_cast<TemplateTypeParmDecl>(Param)) {
1347-
assert(P->hasDefaultArgument() &&
1348-
"expected defaulted template type parameter");
1349-
SpecArgs.emplace_back(P->getDefaultArgument(),
1350-
/*IsNullPtr=*/false,
1351-
/*IsDefaulted=*/true);
1352-
} else if (auto *P = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
1353-
assert(P->hasDefaultArgument() &&
1354-
"expected defaulted template non-type parameter");
1355-
SpecArgs.emplace_back(P->getDefaultArgument(),
1356-
/*IsDefaulted=*/true);
1357-
} else if (auto *P = dyn_cast<TemplateTemplateParmDecl>(Param)) {
1358-
assert(P->hasDefaultArgument() &&
1359-
"expected defaulted template template parameter");
1360-
SpecArgs.emplace_back(
1361-
P->getDefaultArgument().getArgument().getAsTemplate(),
1362-
/*IsDefaulted=*/true);
1363-
} else {
1364-
llvm_unreachable("Unexpected template parameter kind");
1335+
// Skip defaulted args.
1336+
// FIXME: Ideally, we wouldn't do this. We can read the default values
1337+
// for each parameter. However, defaulted arguments which are dependent
1338+
// values or dependent types can't (easily?) be resolved here.
1339+
if (SubstArgs.empty()) {
1340+
// If SubstArgs is now empty (we're taking from it each iteration) and
1341+
// this template parameter isn't a pack, then that should mean we're
1342+
// using default values for the remaining template parameters (after
1343+
// which there may be an empty pack too which we will ignore).
13651344
break;
13661345
}
1346+
1347+
// Take the next argument.
1348+
SpecArgs.push_back(SubstArgs.front());
1349+
SubstArgs = SubstArgs.drop_front();
13671350
}
13681351
return SpecArgs;
13691352
}

clang/test/CodeGenCXX/defaulted-template-alias.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//// Check that -gtemplate-alias causes DW_TAG_template_alias emission for
55
//// template aliases with default parameter values. See template-alias.cpp for
66
//// more template alias tests.
7+
//// FIXME: We currently do not emit defaulted arguments.
78

89
template<typename T>
910
struct X {
@@ -25,9 +26,13 @@ A<int> a;
2526
// CHECK: !DIDerivedType(tag: DW_TAG_template_alias, name: "A", file: ![[#]], line: [[#]], baseType: ![[baseType:[0-9]+]], extraData: ![[extraData:[0-9]+]])
2627
// CHECK: ![[baseType]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "X",
2728
// CHECK: ![[int:[0-9]+]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
28-
// CHECK: ![[extraData]] = !{![[NonDefault:[0-9]+]], ![[T:[0-9]+]], ![[I:[0-9]+]], ![[Ts:[0-9]+]]}
29+
// CHECK: ![[extraData]] = !{![[NonDefault:[0-9]+]]}
2930
// CHECK: ![[NonDefault]] = !DITemplateTypeParameter(name: "NonDefault", type: ![[int]])
30-
// CHECK: ![[T]] = !DITemplateValueParameter(tag: DW_TAG_GNU_template_template_param, name: "T", defaulted: true, value: !"Y")
31-
// CHECK: ![[I]] = !DITemplateValueParameter(name: "I", type: ![[int]], defaulted: true, value: i32 5)
32-
// CHECK: ![[Ts]] = !DITemplateValueParameter(tag: DW_TAG_GNU_template_parameter_pack, name: "Ts", value: ![[types:[0-9]+]])
33-
// CHECK: ![[types]] = !{}
31+
32+
//// FIXME: Ideally, we would describe the deafulted args, like this:
33+
// : ![[extraData]] = !{![[NonDefault:[0-9]+]], ![[T:[0-9]+]], ![[I:[0-9]+]], ![[Ts:[0-9]+]]}
34+
// : ![[NonDefault]] = !DITemplateTypeParameter(name: "NonDefault", type: ![[int]])
35+
// : ![[T]] = !DITemplateValueParameter(tag: DW_TAG_GNU_template_template_param, name: "T", defaulted: true, value: !"Y")
36+
// : ![[I]] = !DITemplateValueParameter(name: "I", type: ![[int]], defaulted: true, value: i32 5)
37+
// : ![[Ts]] = !DITemplateValueParameter(tag: DW_TAG_GNU_template_parameter_pack, name: "Ts", value: ![[types:[0-9]+]])
38+
// : ![[types]] = !{}

0 commit comments

Comments
 (0)