xref: /llvm-project/llvm/test/DebugInfo/X86/debug-info-default-template-parameter.ll (revision 738bfbce09e700124dbcea55b2cfe7f499250b9c)
1*738bfbceSMichael Buch; Tests that DW_AT_default_value is correctly emitted for C++ template
2*738bfbceSMichael Buch; parameters that are defaulted.
3*738bfbceSMichael Buch;
4*738bfbceSMichael Buch; ModuleID = 'debug-info-template-parameter.cpp'
5*738bfbceSMichael Buch;
6*738bfbceSMichael Buch; template <typename T = char, int i = 3, bool b = true, int x = sizeof(T)>
7*738bfbceSMichael Buch; class foo {
8*738bfbceSMichael Buch; };
9*738bfbceSMichael Buch;
10*738bfbceSMichael Buch; int main() {
11*738bfbceSMichael Buch;   foo<int, 6, false, 3> f1;
12*738bfbceSMichael Buch;   foo<> f2;
13*738bfbceSMichael Buch;   return 0;
14*738bfbceSMichael Buch; }
15*738bfbceSMichael Buch;
16*738bfbceSMichael Buch; RUN: llc -filetype=obj -dwarf-version=4 %s -o - | llvm-dwarfdump - --debug-info | FileCheck %s --check-prefixes=DWARF-DUMP,DWARFv4
17*738bfbceSMichael Buch; RUN: llc -filetype=obj -dwarf-version=4 -strict-dwarf=true %s -o - | llvm-dwarfdump - --debug-info | FileCheck %s --check-prefixes=DWARF-DUMP,STRICT
18*738bfbceSMichael Buch
19*738bfbceSMichael Buch; DWARF-DUMP:       DW_TAG_class_type
20*738bfbceSMichael Buch; DWARF-DUMP-LABEL:   DW_AT_name      ("foo<char, 3, true, 1>")
21*738bfbceSMichael Buch; DWARF-DUMP:         DW_TAG_template_type_parameter
22*738bfbceSMichael Buch; DWARF-DUMP-DAG:       DW_AT_type    ({{.*}} "char")
23*738bfbceSMichael Buch; DWARF-DUMP-DAG:       DW_AT_name    ("T")
24*738bfbceSMichael Buch; DWARFv4-DAG:          DW_AT_default_value   (true)
25*738bfbceSMichael Buch; STRICT-NOT:           DW_AT_default_value
26*738bfbceSMichael Buch; DWARF-DUMP:         DW_TAG_template_value_parameter
27*738bfbceSMichael Buch; DWARF-DUMP-DAG:       DW_AT_type    ({{.*}} "int")
28*738bfbceSMichael Buch; DWARF-DUMP-DAG:       DW_AT_name    ("i")
29*738bfbceSMichael Buch; DWARFv4-DAG:          DW_AT_default_value   (true)
30*738bfbceSMichael Buch; STRICT-NOT:           DW_AT_default_value   (true)
31*738bfbceSMichael Buch; DWARF-DUMP:         DW_TAG_template_value_parameter
32*738bfbceSMichael Buch; DWARF-DUMP-DAG:       DW_AT_type    ({{.*}} "bool")
33*738bfbceSMichael Buch; DWARF-DUMP-DAG:       DW_AT_name    ("b")
34*738bfbceSMichael Buch; DWARFv4-DAG:          DW_AT_default_value   (true)
35*738bfbceSMichael Buch; STRICT-NOT:           DW_AT_default_value
36*738bfbceSMichael Buch; DWARF-DUMP:           {{DW_TAG|NULL}}
37*738bfbceSMichael Buch
38*738bfbceSMichael Buchsource_filename = "/tmp/debug-info-template-parameter.cpp"
39*738bfbceSMichael Buchtarget datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
40*738bfbceSMichael Buchtarget triple = "x86_64"
41*738bfbceSMichael Buch
42*738bfbceSMichael Buch%class.foo = type { i8 }
43*738bfbceSMichael Buch%class.foo.0 = type { i8 }
44*738bfbceSMichael Buch
45*738bfbceSMichael Buch; Function Attrs: mustprogress noinline norecurse nounwind optnone
46*738bfbceSMichael Buchdefine dso_local noundef i32 @main() #0 !dbg !6 {
47*738bfbceSMichael Buchentry:
48*738bfbceSMichael Buch  %retval = alloca i32, align 4
49*738bfbceSMichael Buch  %f1 = alloca %class.foo, align 1
50*738bfbceSMichael Buch  %f2 = alloca %class.foo.0, align 1
51*738bfbceSMichael Buch  store i32 0, ptr %retval, align 4
52*738bfbceSMichael Buch  call void @llvm.dbg.declare(metadata ptr %f1, metadata !12, metadata !DIExpression()), !dbg !20
53*738bfbceSMichael Buch  call void @llvm.dbg.declare(metadata ptr %f2, metadata !21, metadata !DIExpression()), !dbg !29
54*738bfbceSMichael Buch  ret i32 0, !dbg !30
55*738bfbceSMichael Buch}
56*738bfbceSMichael Buch
57*738bfbceSMichael Buch; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
58*738bfbceSMichael Buchdeclare void @llvm.dbg.declare(metadata, metadata, metadata) #1
59*738bfbceSMichael Buch
60*738bfbceSMichael Buchattributes #0 = { mustprogress noinline norecurse nounwind optnone "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
61*738bfbceSMichael Buchattributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
62*738bfbceSMichael Buch
63*738bfbceSMichael Buch!llvm.dbg.cu = !{!0}
64*738bfbceSMichael Buch!llvm.linker.options = !{}
65*738bfbceSMichael Buch!llvm.module.flags = !{!2, !3, !4}
66*738bfbceSMichael Buch!llvm.ident = !{!5}
67*738bfbceSMichael Buch
68*738bfbceSMichael Buch!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 16.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
69*738bfbceSMichael Buch!1 = !DIFile(filename: "/tmp/debug-info-template-parameter.cpp", directory: "/")
70*738bfbceSMichael Buch!2 = !{i32 7, !"Dwarf Version", i32 4}
71*738bfbceSMichael Buch!3 = !{i32 2, !"Debug Info Version", i32 3}
72*738bfbceSMichael Buch!4 = !{i32 1, !"wchar_size", i32 4}
73*738bfbceSMichael Buch!5 = !{!"clang version 16.0.0"}
74*738bfbceSMichael Buch!6 = distinct !DISubprogram(name: "main", scope: !7, file: !7, line: 49, type: !8, scopeLine: 49, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !11)
75*738bfbceSMichael Buch!7 = !DIFile(filename: "/tmp/debug-info-template-parameter.cpp", directory: "/")
76*738bfbceSMichael Buch!8 = !DISubroutineType(types: !9)
77*738bfbceSMichael Buch!9 = !{!10}
78*738bfbceSMichael Buch!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
79*738bfbceSMichael Buch!11 = !{}
80*738bfbceSMichael Buch!12 = !DILocalVariable(name: "f1", scope: !6, file: !7, line: 50, type: !13)
81*738bfbceSMichael Buch!13 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "foo<int, 6, false, 3>", file: !7, line: 46, size: 8, flags: DIFlagTypePassByValue, elements: !11, templateParams: !14, identifier: "_ZTS3fooIiLi6ELb0ELi3EE")
82*738bfbceSMichael Buch!14 = !{!15, !16, !17, !19}
83*738bfbceSMichael Buch!15 = !DITemplateTypeParameter(name: "T", type: !10)
84*738bfbceSMichael Buch!16 = !DITemplateValueParameter(name: "i", type: !10, value: i32 6)
85*738bfbceSMichael Buch!17 = !DITemplateValueParameter(name: "b", type: !18, value: i1 false)
86*738bfbceSMichael Buch!18 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean)
87*738bfbceSMichael Buch!19 = !DITemplateValueParameter(name: "x", type: !10, value: i32 3)
88*738bfbceSMichael Buch!20 = !DILocation(line: 50, column: 25, scope: !6)
89*738bfbceSMichael Buch!21 = !DILocalVariable(name: "f2", scope: !6, file: !7, line: 51, type: !22)
90*738bfbceSMichael Buch!22 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "foo<char, 3, true, 1>", file: !7, line: 46, size: 8, flags: DIFlagTypePassByValue, elements: !11, templateParams: !23, identifier: "_ZTS3fooIcLi3ELb1ELi1EE")
91*738bfbceSMichael Buch!23 = !{!24, !26, !27, !28}
92*738bfbceSMichael Buch!24 = !DITemplateTypeParameter(name: "T", type: !25, defaulted: true)
93*738bfbceSMichael Buch!25 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
94*738bfbceSMichael Buch!26 = !DITemplateValueParameter(name: "i", type: !10, defaulted: true, value: i32 3)
95*738bfbceSMichael Buch!27 = !DITemplateValueParameter(name: "b", type: !18, defaulted: true, value: i1 true)
96*738bfbceSMichael Buch!28 = !DITemplateValueParameter(name: "x", type: !10, value: i32 1)
97*738bfbceSMichael Buch!29 = !DILocation(line: 51, column: 9, scope: !6)
98*738bfbceSMichael Buch!30 = !DILocation(line: 52, column: 3, scope: !6)
99