Skip to content

Commit 41f96f9

Browse files
authored
[llvm][DebugInfo] Emit DW_AT_const_value for float non-type template parameters (#127045)
In C++20, non-type template parameters can be float/double. Clang didn't emit those constants in DWARF. This patch emits floating point constants the same way we do other integral template value parameters.
1 parent bcfdae1 commit 41f96f9

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,8 @@ void DwarfUnit::constructTemplateValueParameterDIE(
11471147
if (Metadata *Val = VP->getValue()) {
11481148
if (ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(Val))
11491149
addConstantValue(ParamDIE, CI, VP->getType());
1150+
else if (ConstantFP *CF = mdconst::dyn_extract<ConstantFP>(Val))
1151+
addConstantFPValue(ParamDIE, CF);
11501152
else if (GlobalValue *GV = mdconst::dyn_extract<GlobalValue>(Val)) {
11511153
// We cannot describe the location of dllimport'd entities: the
11521154
// computation of their address requires loads from the IAT.

llvm/test/DebugInfo/X86/debug-info-template-parameter.ll

+29-8
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
; C++ source to regenerate:
55

6-
;template <typename T = char, int i = 3 >
6+
;template <typename T = char, int i = 3, float f = 1.0f, double d = 2.0>
77
;class foo {
88
;};
99
;
1010
;int main() {
11-
; foo<int,6> f1;
11+
; foo<int, 6, 1.9f, 1.9> f1;
1212
; foo<> f2;
1313
; return 0;
1414
;}
@@ -20,21 +20,36 @@
2020

2121
; CHECK: debug_info contents:
2222

23-
; CHECK: DW_AT_name {{.*}} "foo<int, 6>"
23+
; CHECK: DW_AT_name {{.*}} "foo<int, 6, 1.900000e+00, 1.900000e+00>"
2424
; CHECK: DW_AT_type {{.*}} "int"
2525
; CHECK-NEXT: DW_AT_name {{.*}} "T"
2626
; CHECK-NOT: DW_AT_default_value
2727
; CHECK: DW_AT_type {{.*}} "int"
2828
; CHECK-NEXT: DW_AT_name {{.*}} "i"
29+
; CHECK-NEXT: DW_AT_const_value [DW_FORM_sdata] (6)
30+
; CHECK-NOT: DW_AT_default_value
31+
; CHECK: DW_AT_type {{.*}} "float"
32+
; CHECK-NEXT: DW_AT_name {{.*}} "f"
33+
; CHECK-NEXT: DW_AT_const_value [DW_FORM_udata] (1072902963)
34+
; CHECK-NOT: DW_AT_default_value
35+
; CHECK: DW_AT_type {{.*}} "double"
36+
; CHECK-NEXT: DW_AT_name {{.*}} "d"
37+
; CHECK-NEXT: DW_AT_const_value [DW_FORM_udata] (4611235658464650854)
2938
; CHECK-NOT: DW_AT_default_value
3039

31-
; CHECK: DW_AT_name {{.*}} "foo<char, 3>"
40+
; CHECK: DW_AT_name {{.*}} "foo<char, 3, 1.000000e+00, 2.000000e+00>"
3241
; CHECK: DW_AT_type {{.*}} "char"
3342
; CHECK-NEXT: DW_AT_name {{.*}} "T"
3443
; CHECK-NEXT: DW_AT_default_value {{.*}} (true)
3544
; CHECK: DW_AT_type {{.*}} "int"
3645
; CHECK-NEXT: DW_AT_name {{.*}} "i"
3746
; CHECK-NEXT: DW_AT_default_value {{.*}} (true)
47+
; CHECK: DW_AT_type {{.*}} "float"
48+
; CHECK-NEXT: DW_AT_name {{.*}} "f"
49+
; CHECK-NEXT: DW_AT_default_value {{.*}} (true)
50+
; CHECK: DW_AT_type {{.*}} "double"
51+
; CHECK-NEXT: DW_AT_name {{.*}} "d"
52+
; CHECK-NEXT: DW_AT_default_value {{.*}} (true)
3853

3954
; ModuleID = '/dir/test.cpp'
4055
source_filename = "test.cpp"
@@ -76,16 +91,22 @@ attributes #1 = { nounwind readnone speculatable willreturn }
7691
!9 = !{!10}
7792
!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
7893
!11 = !DILocalVariable(name: "f1", scope: !7, file: !1, line: 30, type: !12)
79-
!12 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "foo<int, 6>", file: !1, line: 26, size: 8, flags: DIFlagTypePassByValue, elements: !2, templateParams: !13, identifier: "_ZTS3fooIiLi6EE")
80-
!13 = !{!14, !15}
94+
!12 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "foo<int, 6, 1.900000e+00, 1.900000e+00>", file: !1, line: 26, size: 8, flags: DIFlagTypePassByValue, elements: !2, templateParams: !13, identifier: "_ZTS3fooIiLi6ELf3ff33333ELd3ffe666666666666EE")
95+
!13 = !{!14, !15, !25, !27}
8196
!14 = !DITemplateTypeParameter(name: "T", type: !10)
8297
!15 = !DITemplateValueParameter(name: "i", type: !10, value: i32 6)
8398
!16 = !DILocation(line: 30, column: 14, scope: !7)
8499
!17 = !DILocalVariable(name: "f2", scope: !7, file: !1, line: 31, type: !18)
85-
!18 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "foo<char, 3>", file: !1, line: 26, size: 8, flags: DIFlagTypePassByValue, elements: !2, templateParams: !19, identifier: "_ZTS3fooIcLi3EE")
86-
!19 = !{!20, !22}
100+
!18 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "foo<char, 3, 1.000000e+00, 2.000000e+00>", file: !1, line: 26, size: 8, flags: DIFlagTypePassByValue, elements: !2, templateParams: !19, identifier: "_ZTS3fooIcLi3ELf3f800000ELd4000000000000000EE")
101+
!19 = !{!20, !22, !29, !30}
87102
!20 = !DITemplateTypeParameter(name: "T", type: !21, defaulted: true)
88103
!21 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
89104
!22 = !DITemplateValueParameter(name: "i", type: !10, defaulted: true, value: i32 3)
90105
!23 = !DILocation(line: 31, column: 9, scope: !7)
91106
!24 = !DILocation(line: 32, column: 3, scope: !7)
107+
!25 = !DITemplateValueParameter(name: "f", type: !26, value: float 0x3FFE666660000000)
108+
!26 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float)
109+
!27 = !DITemplateValueParameter(name: "d", type: !28, value: double 1.900000e+00)
110+
!28 = !DIBasicType(name: "double", size: 64, encoding: DW_ATE_float)
111+
!29 = !DITemplateValueParameter(name: "f", type: !26, defaulted: true, value: float 1.000000e+00)
112+
!30 = !DITemplateValueParameter(name: "d", type: !28, defaulted: true, value: double 2.000000e+00)

0 commit comments

Comments
 (0)