Skip to content

Commit bee8860

Browse files
committed
[clang][DebugInfo] Don't canonicalize names in template argument list for alias templates
**Summary** This patch customizes the `CGDebugInfo` printing policy to stop canonicalizing the template arugment list in `DW_AT_name` for alias templates. The motivation for this is that we want to be able to use the `TypePrinter`s support for omitting defaulted template arguments when emitting `DW_AT_name`. For reference, GCC currently completely omits the template arguments when emitting alias template DIEs. **Testing** * Added unit-test Differential Revision: https://reviews.llvm.org/D142268
1 parent d54ae90 commit bee8860

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,9 +1288,21 @@ llvm::DIType *CGDebugInfo::CreateType(const TemplateSpecializationType *Ty,
12881288

12891289
SmallString<128> NS;
12901290
llvm::raw_svector_ostream OS(NS);
1291-
Ty->getTemplateName().print(OS, getPrintingPolicy(),
1292-
TemplateName::Qualified::None);
1293-
printTemplateArgumentList(OS, Ty->template_arguments(), getPrintingPolicy());
1291+
1292+
auto PP = getPrintingPolicy();
1293+
Ty->getTemplateName().print(OS, PP, TemplateName::Qualified::None);
1294+
1295+
// Disable PrintCanonicalTypes here because we want
1296+
// the DW_AT_name to benefit from the TypePrinter's ability
1297+
// to skip defaulted template arguments.
1298+
//
1299+
// FIXME: Once -gsimple-template-names is enabled by default
1300+
// and we attach template parameters to alias template DIEs
1301+
// we don't need to worry about customizing the PrintingPolicy
1302+
// here anymore.
1303+
PP.PrintCanonicalTypes = false;
1304+
printTemplateArgumentList(OS, Ty->template_arguments(), PP,
1305+
TD->getTemplateParameters());
12941306

12951307
SourceLocation Loc = AliasDecl->getLocation();
12961308
return DBuilder.createTypedef(Src, OS.str(), getOrCreateFile(Loc),

clang/test/CodeGenCXX/debug-info-alias.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
template<typename T>
44
struct foo {
55
};
6+
7+
template<typename T, typename T2 = int>
8+
struct baz {
9+
};
10+
611
namespace x {
712
// splitting these over multiple lines to make sure the right token is used for
813
// the location
@@ -18,6 +23,9 @@ x::bar<int> bi;
1823
// CHECK: !DIGlobalVariable(name: "bf",{{.*}} type: [[BFLOAT:![0-9]+]]
1924
// CHECK: [[BFLOAT]] = !DIDerivedType(tag: DW_TAG_typedef, name: "bar<float>"
2025
x::bar<float> bf;
26+
// CHECK: !DIGlobalVariable(name: "bz",{{.*}} type: [[BBAZ:![0-9]+]]
27+
// CHECK: [[BBAZ]] = !DIDerivedType(tag: DW_TAG_typedef, name: "bar<baz<int> >"
28+
x::bar<baz<int>> bz;
2129

2230
using
2331
// CHECK: !DIGlobalVariable(name: "n",{{.*}} type: [[NARF:![0-9]+]]

0 commit comments

Comments
 (0)