Skip to content

[Clang] Fall back to DW_TAG_typedef for instantiation dependent template aliases #90032

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,26 @@ llvm::DIType *CGDebugInfo::CreateType(const TemplateSpecializationType *Ty,

SourceLocation Loc = AliasDecl->getLocation();

if (CGM.getCodeGenOpts().DebugTemplateAlias) {
if (CGM.getCodeGenOpts().DebugTemplateAlias &&
// The TemplateSpecializationType doesn't contain any instantiation
// information; dependent template arguments can't be resolved. For now,
// fall back to DW_TAG_typedefs for template aliases that are
// instantiation dependent, e.g.:
// ```
// template <int>
// using A = int;
//
// template<int I>
// struct S {
// using AA = A<I>; // Instantiation dependent.
// AA aa;
// };
//
// S<0> s;
// ```
// S::AA's underlying type A<I> is dependent on I so will be emitted as a
// DW_TAG_typedef.
!Ty->isInstantiationDependentType()) {
auto ArgVector = ::GetTemplateArgs(TD, Ty);
TemplateArgs Args = {TD->getTemplateParameters(), ArgVector};

Expand Down
21 changes: 21 additions & 0 deletions clang/test/CodeGenCXX/dependent-template-alias.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// RUN: %clang_cc1 -triple x86_64-unk-unk -o - -emit-llvm -debug-info-kind=standalone -gtemplate-alias %s -gsimple-template-names=simple \
// RUN: | FileCheck %s

//// Check that -gtemplate-alias falls back to DW_TAG_typedef emission
//// for instantiation dependent type aliases.

template <int>
using A = int;

template<int I>
struct S {
using AA = A<I>;
AA aa;
};

S<0> s;

// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "aa", scope: ![[#]], file: ![[#]], line: [[#]], baseType: ![[AA:[0-9]+]], size: 32)
// CHECK: [[AA]] = !DIDerivedType(tag: DW_TAG_typedef, name: "AA", file: ![[#]], line: [[#]], baseType: ![[A:[0-9]+]])
// CHECK: [[A]] = !DIDerivedType(tag: DW_TAG_typedef, name: "A<I>", file: ![[#]], line: [[#]], baseType: ![[int:[0-9]+]])
// CHECK: [[int]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)