Skip to content

Commit 87ec4ab

Browse files
authored
[Clang] Fall back to DW_TAG_typedef for instantiation dependent template aliases (#90032)
Workaround for issue #89774 until it can be properly fixed. When `-gtemplate-alias` is specified Clang emits a DW_TAG_template_alias for template aliases. This patch avoids an assertion failure by falling back to the `-gno-template-alias` (default) behaviour, emitting a DW_TAG_typedef, if the alias is instantiation dependent.
1 parent 81442f8 commit 87ec4ab

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,26 @@ llvm::DIType *CGDebugInfo::CreateType(const TemplateSpecializationType *Ty,
13721372

13731373
SourceLocation Loc = AliasDecl->getLocation();
13741374

1375-
if (CGM.getCodeGenOpts().DebugTemplateAlias) {
1375+
if (CGM.getCodeGenOpts().DebugTemplateAlias &&
1376+
// The TemplateSpecializationType doesn't contain any instantiation
1377+
// information; dependent template arguments can't be resolved. For now,
1378+
// fall back to DW_TAG_typedefs for template aliases that are
1379+
// instantiation dependent, e.g.:
1380+
// ```
1381+
// template <int>
1382+
// using A = int;
1383+
//
1384+
// template<int I>
1385+
// struct S {
1386+
// using AA = A<I>; // Instantiation dependent.
1387+
// AA aa;
1388+
// };
1389+
//
1390+
// S<0> s;
1391+
// ```
1392+
// S::AA's underlying type A<I> is dependent on I so will be emitted as a
1393+
// DW_TAG_typedef.
1394+
!Ty->isInstantiationDependentType()) {
13761395
auto ArgVector = ::GetTemplateArgs(TD, Ty);
13771396
TemplateArgs Args = {TD->getTemplateParameters(), ArgVector};
13781397

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %clang_cc1 -triple x86_64-unk-unk -o - -emit-llvm -debug-info-kind=standalone -gtemplate-alias %s -gsimple-template-names=simple \
2+
// RUN: | FileCheck %s
3+
4+
//// Check that -gtemplate-alias falls back to DW_TAG_typedef emission
5+
//// for instantiation dependent type aliases.
6+
7+
template <int>
8+
using A = int;
9+
10+
template<int I>
11+
struct S {
12+
using AA = A<I>;
13+
AA aa;
14+
};
15+
16+
S<0> s;
17+
18+
// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "aa", scope: ![[#]], file: ![[#]], line: [[#]], baseType: ![[AA:[0-9]+]], size: 32)
19+
// CHECK: [[AA]] = !DIDerivedType(tag: DW_TAG_typedef, name: "AA", file: ![[#]], line: [[#]], baseType: ![[A:[0-9]+]])
20+
// CHECK: [[A]] = !DIDerivedType(tag: DW_TAG_typedef, name: "A<I>", file: ![[#]], line: [[#]], baseType: ![[int:[0-9]+]])
21+
// CHECK: [[int]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)

0 commit comments

Comments
 (0)