xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/debug-info-template.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang -S -emit-llvm -target x86_64-unknown_unknown -g %s -o - -std=c++11 | FileCheck %s
2f4a2713aSLionel Sambuc 
3*0a6a1f1dSLionel Sambuc // CHECK: !"0x11\00{{.*}}"{{, [^,]+, [^,]+}}, [[RETAIN:![0-9]*]], {{.*}} ; [ DW_TAG_compile_unit ]
4*0a6a1f1dSLionel Sambuc // CHECK: [[EMPTY:![0-9]*]] = !{}
5*0a6a1f1dSLionel Sambuc // CHECK: [[RETAIN]] = !{!{{[0-9]]*}}, [[FOO:![0-9]*]],
6f4a2713aSLionel Sambuc 
7f4a2713aSLionel Sambuc 
8*0a6a1f1dSLionel Sambuc // CHECK: [[TC:![0-9]*]] = {{.*}}, [[TCARGS:![0-9]*]], !"{{.*}}"} ; [ DW_TAG_structure_type ] [TC<unsigned int, 2, &glb, &foo::e, &foo::f, &foo::g, 1, 2, 3>]
9*0a6a1f1dSLionel Sambuc // CHECK: [[TCARGS]] = !{[[TCARG1:![0-9]*]], [[TCARG2:![0-9]*]], [[TCARG3:![0-9]*]], [[TCARG4:![0-9]*]], [[TCARG5:![0-9]*]], [[TCARG6:![0-9]*]], [[TCARG7:![0-9]*]]}
10f4a2713aSLionel Sambuc //
11f4a2713aSLionel Sambuc // We seem to be missing file/line/col info on template value parameters -
12f4a2713aSLionel Sambuc // metadata supports it but it's not populated. GCC doesn't emit it either,
13f4a2713aSLionel Sambuc // perhaps we should just drop it from the metadata.
14f4a2713aSLionel Sambuc //
15*0a6a1f1dSLionel Sambuc // CHECK: [[TCARG1]] = !{!"0x2f\00T\000\000", null, [[UINT:![0-9]*]], null} ; [ DW_TAG_template_type_parameter ]
16f4a2713aSLionel Sambuc // CHECK: [[UINT:![0-9]*]] = {{.*}} ; [ DW_TAG_base_type ] [unsigned int]
17*0a6a1f1dSLionel Sambuc // CHECK: [[TCARG2]] = !{!"0x30\00\00{{.*}}", {{[^,]+}}, [[UINT]], i32 2, {{.*}} ; [ DW_TAG_template_value_parameter ]
18*0a6a1f1dSLionel Sambuc // CHECK: [[TCARG3]] = !{!"0x30\00x\00{{.*}}", {{[^,]+}}, [[CINTPTR:![0-9]*]], i32* @glb, {{.*}} ; [ DW_TAG_template_value_parameter ]
19*0a6a1f1dSLionel Sambuc // CHECK: [[CINTPTR]] = {{.*}}, [[CINT:![0-9]*]]} ; [ DW_TAG_pointer_type ] {{.*}} [from ]
20*0a6a1f1dSLionel Sambuc // CHECK: [[CINT]] = {{.*}}, [[INT:![0-9]*]]} ; [ DW_TAG_const_type ] {{.*}} [from int]
21f4a2713aSLionel Sambuc // CHECK: [[INT]] = {{.*}} ; [ DW_TAG_base_type ] [int]
22*0a6a1f1dSLionel Sambuc // CHECK: [[TCARG4]] = !{!"0x30\00a\00{{.*}}", {{[^,]+}}, [[MEMINTPTR:![0-9]*]], i64 8, {{.*}} ; [ DW_TAG_template_value_parameter ]
23*0a6a1f1dSLionel Sambuc // CHECK: [[MEMINTPTR]] = {{.*}}, !"_ZTS3foo"} ; [ DW_TAG_ptr_to_member_type ] {{.*}}[from int]
24f4a2713aSLionel Sambuc //
25f4a2713aSLionel Sambuc // Currently Clang emits the pointer-to-member-function value, but LLVM doesn't
26f4a2713aSLionel Sambuc // use it (GCC doesn't emit a value for pointers to member functions either - so
27f4a2713aSLionel Sambuc // it's not clear what, if any, format would be acceptable to GDB)
28f4a2713aSLionel Sambuc //
29*0a6a1f1dSLionel Sambuc // CHECK: [[TCARG5]] = !{!"0x30\00b\00{{.*}}", {{[^,]+}}, [[MEMFUNPTR:![0-9]*]], { i64, i64 } { i64 ptrtoint (void (%struct.foo*)* @_ZN3foo1fEv to i64), i64 0 }, {{.*}} ; [ DW_TAG_template_value_parameter ]
30*0a6a1f1dSLionel Sambuc // CHECK: [[MEMFUNPTR]] = {{.*}}, [[FTYPE:![0-9]*]], !"_ZTS3foo"} ; [ DW_TAG_ptr_to_member_type ]
31*0a6a1f1dSLionel Sambuc // CHECK: [[FTYPE]] = {{.*}}, [[FARGS:![0-9]*]], null, null, null} ; [ DW_TAG_subroutine_type ]
32*0a6a1f1dSLionel Sambuc // CHECK: [[FARGS]] = !{null, [[FARG1:![0-9]*]]}
33f4a2713aSLionel Sambuc // CHECK: [[FARG1]] = {{.*}} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [artificial] [from _ZTS3foo]
34f4a2713aSLionel Sambuc //
35*0a6a1f1dSLionel Sambuc // CHECK: [[TCARG6]] = !{!"0x30\00f\00{{.*}}", {{[^,]+}}, [[FUNPTR:![0-9]*]], void ()* @_ZN3foo1gEv, {{.*}} ; [ DW_TAG_template_value_parameter ]
36*0a6a1f1dSLionel Sambuc // CHECK: [[FUNPTR]] = {{.*}}, [[FUNTYPE:![0-9]*]]} ; [ DW_TAG_pointer_type ]
37*0a6a1f1dSLionel Sambuc // CHECK: [[FUNTYPE]] = {{.*}}, [[FUNARGS:![0-9]*]], null, null, null} ; [ DW_TAG_subroutine_type ]
38*0a6a1f1dSLionel Sambuc // CHECK: [[FUNARGS]] = !{null}
39*0a6a1f1dSLionel Sambuc // CHECK: [[TCARG7]] = !{!"0x4107\00Is\000\000", null, null, [[TCARG7_VALS:![0-9]*]], null} ; [ DW_TAG_GNU_template_parameter_pack ]
40*0a6a1f1dSLionel Sambuc // CHECK: [[TCARG7_VALS]] = !{[[TCARG7_1:![0-9]*]], [[TCARG7_2:![0-9]*]], [[TCARG7_3:![0-9]*]]}
41*0a6a1f1dSLionel Sambuc // CHECK: [[TCARG7_1]] = !{!"0x30\00\00{{.*}}", {{[^,]+}}, [[INT]], i32 1, {{.*}} ; [ DW_TAG_template_value_parameter ]
42*0a6a1f1dSLionel Sambuc // CHECK: [[TCARG7_2]] = !{!"0x30\00\00{{.*}}", {{[^,]+}}, [[INT]], i32 2, {{.*}} ; [ DW_TAG_template_value_parameter ]
43*0a6a1f1dSLionel Sambuc // CHECK: [[TCARG7_3]] = !{!"0x30\00\00{{.*}}", {{[^,]+}}, [[INT]], i32 3, {{.*}} ; [ DW_TAG_template_value_parameter ]
44f4a2713aSLionel Sambuc //
45f4a2713aSLionel Sambuc // We could just emit a declaration of 'foo' here, rather than the entire
46f4a2713aSLionel Sambuc // definition (same goes for any time we emit a member (function or data)
47f4a2713aSLionel Sambuc // pointer type)
48*0a6a1f1dSLionel Sambuc // CHECK: [[FOO]] = {{.*}}, !"_ZTS3foo"} ; [ DW_TAG_structure_type ] [foo]
49*0a6a1f1dSLionel Sambuc // CHECK: !"0x2e\00f\00f\00_ZN3foo1fEv\00{{.*}}", [[FTYPE:![0-9]*]], {{.*}} ; [ DW_TAG_subprogram ]
50f4a2713aSLionel Sambuc //
51f4a2713aSLionel Sambuc 
52*0a6a1f1dSLionel Sambuc // CHECK:  !"0x13\00{{.*}}", !{{[0-9]*}}, !"_ZTS2TCIjLj2EXadL_Z3glbEEXadL_ZN3foo1eEEEXadL_ZNS0_1fEvEEXadL_ZNS0_1gEvEEJLi1ELi2ELi3EEE", {{.*}}, !"[[TCNESTED:.*]]"} ; [ DW_TAG_structure_type ] [nested]
53*0a6a1f1dSLionel Sambuc // CHECK: [[TCNARGS:![0-9]*]], !"[[TCNT:.*]]"} ; [ DW_TAG_structure_type ] [TC<int, -3, nullptr, nullptr, nullptr, nullptr>]
54*0a6a1f1dSLionel Sambuc // CHECK: [[TCNARGS]] = !{[[TCNARG1:![0-9]*]], [[TCNARG2:![0-9]*]], [[TCNARG3:![0-9]*]], [[TCNARG4:![0-9]*]], [[TCNARG5:![0-9]*]], [[TCNARG6:![0-9]*]], [[TCNARG7:![0-9]*]]}
55*0a6a1f1dSLionel Sambuc // CHECK: [[TCNARG1]] = !{!"0x2f\00T\000\000", null, [[INT]], null} ; [ DW_TAG_template_type_parameter ]
56*0a6a1f1dSLionel Sambuc // CHECK: [[TCNARG2]] = !{!"0x30\00\000\000", null, [[INT]], i32 -3, null} ; [ DW_TAG_template_value_parameter ]
57*0a6a1f1dSLionel Sambuc // CHECK: [[TCNARG3]] = !{!"0x30\00x\000\000", null, [[CINTPTR]], i8 0, null} ; [ DW_TAG_template_value_parameter ]
58f4a2713aSLionel Sambuc 
59f4a2713aSLionel Sambuc // The interesting null pointer: -1 for member data pointers (since they are
60f4a2713aSLionel Sambuc // just an offset in an object, they can be zero and non-null for the first
61f4a2713aSLionel Sambuc // member)
62f4a2713aSLionel Sambuc 
63*0a6a1f1dSLionel Sambuc // CHECK: [[TCNARG4]] = !{!"0x30\00a\000\000", null, [[MEMINTPTR]], i64 -1, null} ; [ DW_TAG_template_value_parameter ]
64f4a2713aSLionel Sambuc //
65f4a2713aSLionel Sambuc // In some future iteration we could possibly emit the value of a null member
66f4a2713aSLionel Sambuc // function pointer as '{ i64, i64 } zeroinitializer' as it may be handled
67f4a2713aSLionel Sambuc // naturally from the LLVM CodeGen side once we decide how to handle non-null
68f4a2713aSLionel Sambuc // member function pointers. For now, it's simpler just to emit the 'i8 0'.
69f4a2713aSLionel Sambuc //
70*0a6a1f1dSLionel Sambuc // CHECK: [[TCNARG5]] = !{!"0x30\00b\000\000", null, [[MEMFUNPTR]], i8 0, null} ; [ DW_TAG_template_value_parameter ]
71*0a6a1f1dSLionel Sambuc // CHECK: [[TCNARG6]] = !{!"0x30\00f\000\000", null, [[FUNPTR]], i8 0, null} ; [ DW_TAG_template_value_parameter ]
72*0a6a1f1dSLionel Sambuc // CHECK: [[TCNARG7]] = !{!"0x4107\00Is\000\000", null, null, [[EMPTY]], null} ; [ DW_TAG_GNU_template_parameter_pack ]
73f4a2713aSLionel Sambuc 
74*0a6a1f1dSLionel Sambuc // FIXME: these parameters should probably be rendered as 'glb' rather than
75*0a6a1f1dSLionel Sambuc // '&glb', since they're references, not pointers.
76*0a6a1f1dSLionel Sambuc // CHECK: [[NNARGS:![0-9]*]], !"[[NNT:.*]]"} ; [ DW_TAG_structure_type ] [NN<tmpl_impl, &glb, &glb>]
77*0a6a1f1dSLionel Sambuc // CHECK: [[NNARGS]] = !{[[NNARG1:![0-9]*]], [[NNARG2:![0-9]*]], [[NNARG3:![0-9]*]]}
78*0a6a1f1dSLionel Sambuc // CHECK: [[NNARG1]] = !{!"0x4106\00tmpl\000\000", null, null, !"tmpl_impl", null} ; [ DW_TAG_GNU_template_template_param ]
79*0a6a1f1dSLionel Sambuc // CHECK: [[NNARG2]] = !{!"0x30\00lvr\00{{.*}}", {{[^,]+}}, [[INTLVR:![0-9]*]], i32* @glb, {{.*}} ; [ DW_TAG_template_value_parameter ]
80*0a6a1f1dSLionel Sambuc // CHECK: [[INTLVR]] = {{.*}}, [[INT]]} ; [ DW_TAG_reference_type ] {{.*}} [from int]
81*0a6a1f1dSLionel Sambuc // CHECK: [[NNARG3]] = !{!"0x30\00rvr\00{{.*}}", {{[^,]+}}, [[INTRVR:![0-9]*]], i32* @glb, {{.*}} ; [ DW_TAG_template_value_parameter ]
82*0a6a1f1dSLionel Sambuc // CHECK: [[INTRVR]] = {{.*}}, [[INT]]} ; [ DW_TAG_rvalue_reference_type ] {{.*}} [from int]
83*0a6a1f1dSLionel Sambuc 
84*0a6a1f1dSLionel Sambuc // CHECK: [[PTOARGS:![0-9]*]], !"{{.*}}"} ; [ DW_TAG_structure_type ] [PaddingAtEndTemplate<&PaddedObj>]
85*0a6a1f1dSLionel Sambuc // CHECK: [[PTOARGS]] = !{[[PTOARG1:![0-9]*]]}
86*0a6a1f1dSLionel Sambuc // CHECK: [[PTOARG1]] = !{!"0x30\00\000\000", null, [[CONST_PADDINGATEND_PTR:![0-9]*]], %struct.PaddingAtEnd* @PaddedObj, null} ; [ DW_TAG_template_value_parameter ]
87f4a2713aSLionel Sambuc // CHECK: [[CONST_PADDINGATEND_PTR]] = {{.*}} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [from _ZTS12PaddingAtEnd]
88f4a2713aSLionel Sambuc 
89*0a6a1f1dSLionel Sambuc // CHECK: !"[[TCNESTED]]", %"struct.TC<unsigned int, 2, &glb, &foo::e, &foo::f, &foo::g, 1, 2, 3>::nested"* @tci, null} ; [ DW_TAG_variable ] [tci]
90f4a2713aSLionel Sambuc 
91*0a6a1f1dSLionel Sambuc // CHECK: !"[[TCNT]]", %struct.TC* @tcn, null} ; [ DW_TAG_variable ] [tcn]
92*0a6a1f1dSLionel Sambuc 
93*0a6a1f1dSLionel Sambuc // CHECK: !"[[NNT]]", %struct.NN* @nn, null} ; [ DW_TAG_variable ] [nn]
94f4a2713aSLionel Sambuc struct foo {
95f4a2713aSLionel Sambuc   char pad[8]; // make the member pointer to 'e' a bit more interesting (nonzero)
96f4a2713aSLionel Sambuc   int e;
97f4a2713aSLionel Sambuc   void f();
98*0a6a1f1dSLionel Sambuc   static void g();
99f4a2713aSLionel Sambuc };
100f4a2713aSLionel Sambuc 
101*0a6a1f1dSLionel Sambuc typedef int foo::*foo_mem;
102*0a6a1f1dSLionel Sambuc 
103*0a6a1f1dSLionel Sambuc template<typename T, T, const int *x, foo_mem a, void (foo::*b)(), void (*f)(), int ...Is>
104f4a2713aSLionel Sambuc struct TC {
105f4a2713aSLionel Sambuc   struct nested {
106f4a2713aSLionel Sambuc   };
107f4a2713aSLionel Sambuc };
108f4a2713aSLionel Sambuc 
109f4a2713aSLionel Sambuc int glb;
110f4a2713aSLionel Sambuc void func();
111f4a2713aSLionel Sambuc 
112*0a6a1f1dSLionel Sambuc TC<unsigned, 2, &glb, &foo::e, &foo::f, &foo::g, 1, 2, 3>::nested tci;
113*0a6a1f1dSLionel Sambuc TC<int, -3, nullptr, nullptr, nullptr, nullptr> tcn;
114*0a6a1f1dSLionel Sambuc 
115f4a2713aSLionel Sambuc template<typename>
116f4a2713aSLionel Sambuc struct tmpl_impl {
117f4a2713aSLionel Sambuc };
118f4a2713aSLionel Sambuc 
119*0a6a1f1dSLionel Sambuc template <template <typename> class tmpl, int &lvr, int &&rvr>
120*0a6a1f1dSLionel Sambuc struct NN {
121*0a6a1f1dSLionel Sambuc };
122*0a6a1f1dSLionel Sambuc 
123*0a6a1f1dSLionel Sambuc NN<tmpl_impl, glb, glb> nn;
124f4a2713aSLionel Sambuc 
125f4a2713aSLionel Sambuc struct PaddingAtEnd {
126f4a2713aSLionel Sambuc   int i;
127f4a2713aSLionel Sambuc   char c;
128f4a2713aSLionel Sambuc };
129f4a2713aSLionel Sambuc 
130f4a2713aSLionel Sambuc PaddingAtEnd PaddedObj = {};
131f4a2713aSLionel Sambuc 
132*0a6a1f1dSLionel Sambuc template <PaddingAtEnd *>
133f4a2713aSLionel Sambuc struct PaddingAtEndTemplate {
134f4a2713aSLionel Sambuc };
135f4a2713aSLionel Sambuc 
136f4a2713aSLionel Sambuc PaddingAtEndTemplate<&PaddedObj> PaddedTemplateObj;
137