xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/debug-info-template-member.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -emit-llvm -g -fno-standalone-debug -triple x86_64-apple-darwin %s -o - | FileCheck %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc struct MyClass {
addMyClass4f4a2713aSLionel Sambuc   template <int i> int add(int j) {
5f4a2713aSLionel Sambuc     return i + j;
6f4a2713aSLionel Sambuc   }
funcMyClass7f4a2713aSLionel Sambuc   virtual void func() {
8f4a2713aSLionel Sambuc   }
9f4a2713aSLionel Sambuc };
10f4a2713aSLionel Sambuc 
add2(int x)11f4a2713aSLionel Sambuc int add2(int x) {
12f4a2713aSLionel Sambuc   return MyClass().add<2>(x);
13f4a2713aSLionel Sambuc }
14f4a2713aSLionel Sambuc 
add3(int x)15f4a2713aSLionel Sambuc inline int add3(int x) {
16f4a2713aSLionel Sambuc   return MyClass().add<3>(x); // even though add<3> is ODR used, don't emit it since we don't codegen it
17f4a2713aSLionel Sambuc }
18f4a2713aSLionel Sambuc 
19*0a6a1f1dSLionel Sambuc // CHECK: [[FOO_MEM:![0-9]*]], null, null, !"_ZTS3foo"} ; [ DW_TAG_structure_type ] [foo]
20*0a6a1f1dSLionel Sambuc // CHECK: [[FOO_MEM]] = !{[[FOO_FUNC:![0-9]*]]}
21*0a6a1f1dSLionel Sambuc // CHECK: [[FOO_FUNC]] = !{!"0x2e\00func\00func\00_ZN3foo4funcEN5outerIS_E5innerE\00{{.*}}"{{, [^,]+, [^,]+}}, [[FOO_FUNC_TYPE:![0-9]*]], {{.*}} ; [ DW_TAG_subprogram ] {{.*}} [func]
22*0a6a1f1dSLionel Sambuc // CHECK: [[FOO_FUNC_TYPE]] = {{.*}}, [[FOO_FUNC_PARAMS:![0-9]*]], null, null, null} ; [ DW_TAG_subroutine_type ]
23*0a6a1f1dSLionel Sambuc // CHECK: [[FOO_FUNC_PARAMS]] = !{null, !{{[0-9]*}}, !"[[OUTER_FOO_INNER_ID:.*]]"}
24*0a6a1f1dSLionel Sambuc // CHECK: !{{[0-9]*}} = {{.*}}, null, !"[[OUTER_FOO_INNER_ID]]"} ; [ DW_TAG_structure_type ] [inner]
25f4a2713aSLionel Sambuc 
26*0a6a1f1dSLionel Sambuc // CHECK: [[VIRT_MEM:![0-9]*]], !"_ZTS4virtI4elemE", [[VIRT_TEMP_PARAM:![0-9]*]], !"_ZTS4virtI4elemE"} ; [ DW_TAG_structure_type ] [virt<elem>] {{.*}} [def]
27*0a6a1f1dSLionel Sambuc // CHECK: [[VIRT_TEMP_PARAM]] = !{[[VIRT_T:![0-9]*]]}
28*0a6a1f1dSLionel Sambuc // CHECK: [[VIRT_T]] = !{!"0x2f\00T\000\000"{{, [^,]+}}, !"_ZTS4elem", {{.*}} ; [ DW_TAG_template_type_parameter ]
29f4a2713aSLionel Sambuc 
30*0a6a1f1dSLionel Sambuc // CHECK: [[C:![0-9]*]] = {{.*}}, [[C_MEM:![0-9]*]], !"_ZTS7MyClass", null, !"_ZTS7MyClass"} ; [ DW_TAG_structure_type ] [MyClass]
31*0a6a1f1dSLionel Sambuc // CHECK: [[C_MEM]] = !{[[C_VPTR:![0-9]*]], [[C_FUNC:![0-9]*]]}
32f4a2713aSLionel Sambuc // CHECK: [[C_VPTR]] = {{.*}} ; [ DW_TAG_member ] [_vptr$MyClass]
33f4a2713aSLionel Sambuc 
34f4a2713aSLionel Sambuc // CHECK: [[C_FUNC]] = {{.*}} ; [ DW_TAG_subprogram ] [line 7] [func]
35f4a2713aSLionel Sambuc 
36*0a6a1f1dSLionel Sambuc // CHECK: [[ELEM:![0-9]*]] = {{.*}}, [[ELEM_MEM:![0-9]*]], null, null, !"_ZTS4elem"} ; [ DW_TAG_structure_type ] [elem] {{.*}} [def]
37*0a6a1f1dSLionel Sambuc // CHECK: [[ELEM_MEM]] = !{[[ELEM_X:![0-9]*]]}
38f4a2713aSLionel Sambuc // CHECK: [[ELEM_X]] = {{.*}} ; [ DW_TAG_member ] [x] {{.*}} [static] [from _ZTS4virtI4elemE]
39f4a2713aSLionel Sambuc 
40*0a6a1f1dSLionel Sambuc // Check that the member function template specialization and implicit special
41*0a6a1f1dSLionel Sambuc // members (the default ctor) refer to their class by scope, even though they
42*0a6a1f1dSLionel Sambuc // didn't appear in the class's member list (C_MEM). This prevents the functions
43*0a6a1f1dSLionel Sambuc // from being added to type units, while still appearing in the type
44*0a6a1f1dSLionel Sambuc // declaration/reference in the compile unit.
45*0a6a1f1dSLionel Sambuc // CHECK: !"_ZTS7MyClass", {{.*}} ; [ DW_TAG_subprogram ] [line 4] [add<2>]
46*0a6a1f1dSLionel Sambuc // CHECK: !"_ZTS7MyClass", {{.*}} ; [ DW_TAG_subprogram ] [line 0] [MyClass]
47*0a6a1f1dSLionel Sambuc 
48f4a2713aSLionel Sambuc template<typename T>
49f4a2713aSLionel Sambuc struct outer {
50f4a2713aSLionel Sambuc   struct inner {
51f4a2713aSLionel Sambuc     int i;
52f4a2713aSLionel Sambuc   };
53f4a2713aSLionel Sambuc };
54f4a2713aSLionel Sambuc 
55f4a2713aSLionel Sambuc struct foo {
56f4a2713aSLionel Sambuc   void func(outer<foo>::inner);
57f4a2713aSLionel Sambuc };
58f4a2713aSLionel Sambuc 
func()59f4a2713aSLionel Sambuc inline void func() {
60f4a2713aSLionel Sambuc   // require 'foo' to be complete before the emission of 'inner' so that, when
61f4a2713aSLionel Sambuc   // constructing the context chain for 'x' we emit the full definition of
62f4a2713aSLionel Sambuc   // 'foo', which requires the definition of 'inner' again
63f4a2713aSLionel Sambuc   foo f;
64f4a2713aSLionel Sambuc }
65f4a2713aSLionel Sambuc 
66f4a2713aSLionel Sambuc outer<foo>::inner x;
67f4a2713aSLionel Sambuc 
68*0a6a1f1dSLionel Sambuc // CHECK:  !"0x34\00{{.*}}", {{.*}}, !"[[OUTER_FOO_INNER_ID]]", %"struct.outer<foo>::inner"* @x, {{.*}} ; [ DW_TAG_variable ] [x]
69f4a2713aSLionel Sambuc 
70f4a2713aSLionel Sambuc template <typename T>
71f4a2713aSLionel Sambuc struct virt {
72f4a2713aSLionel Sambuc   T* values;
73f4a2713aSLionel Sambuc   virtual ~virt();
74f4a2713aSLionel Sambuc };
75f4a2713aSLionel Sambuc struct elem {
76f4a2713aSLionel Sambuc   static virt<elem> x; // ensure that completing 'elem' will require/completing 'virt<elem>'
77f4a2713aSLionel Sambuc };
f1()78f4a2713aSLionel Sambuc inline void f1() {
79f4a2713aSLionel Sambuc   elem e; // ensure 'elem' is required to be complete when it is emitted as a template argument for 'virt<elem>'
80f4a2713aSLionel Sambuc };
f2()81f4a2713aSLionel Sambuc void f2() {
82f4a2713aSLionel Sambuc   virt<elem> d; // emit 'virt<elem>'
83f4a2713aSLionel Sambuc }
84f4a2713aSLionel Sambuc 
85