Skip to content

Commit 1cb0e01

Browse files
Awanish PandeySouraVX
authored andcommitted
[DebugInfo][DWARF5]: Added support for debuginfo generation for defaulted parameters
This patch adds support for dwarf emission/dumping part of debuginfo generation for defaulted parameters. Reviewers: probinson, aprantl, dblaikie Reviewed By: aprantl, dblaikie Differential Revision: https://reviews.llvm.org/D73462
1 parent 534d886 commit 1cb0e01

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Test for DebugInfo for Defaulted parameters for C++ templates
2+
// Supported: -O0, standalone DI
3+
4+
// RUN: %clang_cc1 -dwarf-version=5 -emit-llvm -triple x86_64-linux-gnu %s -o - \
5+
// RUN: -O0 -disable-llvm-passes \
6+
// RUN: -debug-info-kind=standalone \
7+
// RUN: | FileCheck %s
8+
9+
// CHECK: DILocalVariable(name: "f1", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
10+
// CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: ![[F1_TYPE:[0-9]+]]
11+
// CHECK: [[F1_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]]}
12+
// CHECK: [[FIRST]] = !DITemplateTypeParameter(name: "T", type: !{{[0-9]*}})
13+
// CHECK: [[SECOND]] = !DITemplateValueParameter(name: "i", type: !{{[0-9]*}}, value: i32 6)
14+
15+
// CHECK: DILocalVariable(name: "f2", {{.*}}, type: ![[TEMPLATE_TYPE:[0-9]+]]
16+
// CHECK: [[TEMPLATE_TYPE]] = {{.*}}!DICompositeType({{.*}}, templateParams: ![[F2_TYPE:[0-9]+]]
17+
// CHECK: [[F2_TYPE]] = !{![[FIRST:[0-9]+]], ![[SECOND:[0-9]+]]}
18+
// CHECK: [[FIRST]] = !DITemplateTypeParameter(name: "T", type: !{{[0-9]*}}, defaulted: true)
19+
// CHECK: [[SECOND]] = !DITemplateValueParameter(name: "i", type: !{{[0-9]*}}, defaulted: true, value: i32 3)
20+
21+
template <typename T = char, int i = 3>
22+
class foo {
23+
};
24+
25+
int main() {
26+
foo<int, 6> f1;
27+
foo<> f2;
28+
return 0;
29+
}

llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,8 @@ void DwarfUnit::constructTemplateTypeParameterDIE(
10451045
addType(ParamDIE, TP->getType());
10461046
if (!TP->getName().empty())
10471047
addString(ParamDIE, dwarf::DW_AT_name, TP->getName());
1048+
if (TP->isDefault() && (DD->getDwarfVersion() >= 5))
1049+
addFlag(ParamDIE, dwarf::DW_AT_default_value);
10481050
}
10491051

10501052
void DwarfUnit::constructTemplateValueParameterDIE(
@@ -1057,6 +1059,8 @@ void DwarfUnit::constructTemplateValueParameterDIE(
10571059
addType(ParamDIE, VP->getType());
10581060
if (!VP->getName().empty())
10591061
addString(ParamDIE, dwarf::DW_AT_name, VP->getName());
1062+
if (VP->isDefault() && (DD->getDwarfVersion() >= 5))
1063+
addFlag(ParamDIE, dwarf::DW_AT_default_value);
10601064
if (Metadata *Val = VP->getValue()) {
10611065
if (ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(Val))
10621066
addConstantValue(ParamDIE, CI, VP->getType());

0 commit comments

Comments
 (0)