xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/debug-info-template-member.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -emit-llvm -g -triple x86_64-apple-darwin %s -o - | FileCheck %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc struct MyClass {
4*f4a2713aSLionel Sambuc   template <int i> int add(int j) {
5*f4a2713aSLionel Sambuc     return i + j;
6*f4a2713aSLionel Sambuc   }
7*f4a2713aSLionel Sambuc   virtual void func() {
8*f4a2713aSLionel Sambuc   }
9*f4a2713aSLionel Sambuc };
10*f4a2713aSLionel Sambuc 
11*f4a2713aSLionel Sambuc int add2(int x) {
12*f4a2713aSLionel Sambuc   return MyClass().add<2>(x);
13*f4a2713aSLionel Sambuc }
14*f4a2713aSLionel Sambuc 
15*f4a2713aSLionel Sambuc inline int add3(int x) {
16*f4a2713aSLionel Sambuc   return MyClass().add<3>(x); // even though add<3> is ODR used, don't emit it since we don't codegen it
17*f4a2713aSLionel Sambuc }
18*f4a2713aSLionel Sambuc 
19*f4a2713aSLionel Sambuc // CHECK: [[FOO_MEM:![0-9]*]], i32 0, null, null, metadata !"_ZTS3foo"} ; [ DW_TAG_structure_type ] [foo]
20*f4a2713aSLionel Sambuc // CHECK: [[FOO_MEM]] = metadata !{metadata [[FOO_FUNC:![0-9]*]]}
21*f4a2713aSLionel Sambuc // CHECK: [[FOO_FUNC]] = {{.*}}, metadata !"_ZN3foo4funcEN5outerIS_E5innerE", i32 {{[0-9]*}}, metadata [[FOO_FUNC_TYPE:![0-9]*]], {{.*}} ; [ DW_TAG_subprogram ] {{.*}} [func]
22*f4a2713aSLionel Sambuc // CHECK: [[FOO_FUNC_TYPE]] = {{.*}}, metadata [[FOO_FUNC_PARAMS:![0-9]*]], i32 0, null, null, null} ; [ DW_TAG_subroutine_type ]
23*f4a2713aSLionel Sambuc // CHECK: [[FOO_FUNC_PARAMS]] = metadata !{null, metadata !{{[0-9]*}}, metadata [[OUTER_FOO_INNER:![0-9]*]]}
24*f4a2713aSLionel Sambuc // CHECK: [[OUTER_FOO_INNER]] = {{.*}} ; [ DW_TAG_structure_type ] [inner]
25*f4a2713aSLionel Sambuc 
26*f4a2713aSLionel Sambuc // CHECK: metadata [[VIRT_MEM:![0-9]*]], i32 0, metadata !"_ZTS4virtI4elemE", metadata [[VIRT_TEMP_PARAM:![0-9]*]], metadata !"_ZTS4virtI4elemE"} ; [ DW_TAG_structure_type ] [virt<elem>] {{.*}} [def]
27*f4a2713aSLionel Sambuc // CHECK: [[VIRT_TEMP_PARAM]] = metadata !{metadata [[VIRT_T:![0-9]*]]}
28*f4a2713aSLionel Sambuc // CHECK: [[VIRT_T]] = {{.*}}, metadata !"T", metadata !"_ZTS4elem", {{.*}} ; [ DW_TAG_template_type_parameter ]
29*f4a2713aSLionel Sambuc 
30*f4a2713aSLionel Sambuc // CHECK: [[C:![0-9]*]] = {{.*}}, metadata [[C_MEM:![0-9]*]], i32 0, metadata !"_ZTS7MyClass", null, metadata !"_ZTS7MyClass"} ; [ DW_TAG_structure_type ] [MyClass]
31*f4a2713aSLionel Sambuc // CHECK: [[C_MEM]] = metadata !{metadata [[C_VPTR:![0-9]*]], metadata [[C_ADD:![0-9]*]], metadata [[C_FUNC:![0-9]*]], metadata [[C_CTOR:![0-9]*]]}
32*f4a2713aSLionel Sambuc // CHECK: [[C_VPTR]] = {{.*}} ; [ DW_TAG_member ] [_vptr$MyClass]
33*f4a2713aSLionel Sambuc 
34*f4a2713aSLionel Sambuc // CHECK: [[C_ADD]] = {{.*}} ; [ DW_TAG_subprogram ] [line 4] [add<2>]
35*f4a2713aSLionel Sambuc // CHECK: [[C_FUNC]] = {{.*}} ; [ DW_TAG_subprogram ] [line 7] [func]
36*f4a2713aSLionel Sambuc // CHECK: [[C_CTOR]] = {{.*}} ; [ DW_TAG_subprogram ] [line 0] [MyClass]
37*f4a2713aSLionel Sambuc 
38*f4a2713aSLionel Sambuc // CHECK: [[ELEM:![0-9]*]] = {{.*}}, metadata [[ELEM_MEM:![0-9]*]], i32 0, null, null, metadata !"_ZTS4elem"} ; [ DW_TAG_structure_type ] [elem] {{.*}} [def]
39*f4a2713aSLionel Sambuc // CHECK: [[ELEM_MEM]] = metadata !{metadata [[ELEM_X:![0-9]*]]}
40*f4a2713aSLionel Sambuc // CHECK: [[ELEM_X]] = {{.*}} ; [ DW_TAG_member ] [x] {{.*}} [static] [from _ZTS4virtI4elemE]
41*f4a2713aSLionel Sambuc 
42*f4a2713aSLionel Sambuc template<typename T>
43*f4a2713aSLionel Sambuc struct outer {
44*f4a2713aSLionel Sambuc   struct inner {
45*f4a2713aSLionel Sambuc     int i;
46*f4a2713aSLionel Sambuc   };
47*f4a2713aSLionel Sambuc };
48*f4a2713aSLionel Sambuc 
49*f4a2713aSLionel Sambuc struct foo {
50*f4a2713aSLionel Sambuc   void func(outer<foo>::inner);
51*f4a2713aSLionel Sambuc };
52*f4a2713aSLionel Sambuc 
53*f4a2713aSLionel Sambuc inline void func() {
54*f4a2713aSLionel Sambuc   // require 'foo' to be complete before the emission of 'inner' so that, when
55*f4a2713aSLionel Sambuc   // constructing the context chain for 'x' we emit the full definition of
56*f4a2713aSLionel Sambuc   // 'foo', which requires the definition of 'inner' again
57*f4a2713aSLionel Sambuc   foo f;
58*f4a2713aSLionel Sambuc }
59*f4a2713aSLionel Sambuc 
60*f4a2713aSLionel Sambuc outer<foo>::inner x;
61*f4a2713aSLionel Sambuc 
62*f4a2713aSLionel Sambuc // CHECK: metadata [[OUTER_FOO_INNER]], i32 {{[0-9]*}}, i32 {{[0-9]*}}, %"struct.outer<foo>::inner"* @x, {{.*}} ; [ DW_TAG_variable ] [x]
63*f4a2713aSLionel Sambuc 
64*f4a2713aSLionel Sambuc template <typename T>
65*f4a2713aSLionel Sambuc struct virt {
66*f4a2713aSLionel Sambuc   T* values;
67*f4a2713aSLionel Sambuc   virtual ~virt();
68*f4a2713aSLionel Sambuc };
69*f4a2713aSLionel Sambuc struct elem {
70*f4a2713aSLionel Sambuc   static virt<elem> x; // ensure that completing 'elem' will require/completing 'virt<elem>'
71*f4a2713aSLionel Sambuc };
72*f4a2713aSLionel Sambuc inline void f1() {
73*f4a2713aSLionel Sambuc   elem e; // ensure 'elem' is required to be complete when it is emitted as a template argument for 'virt<elem>'
74*f4a2713aSLionel Sambuc };
75*f4a2713aSLionel Sambuc void f2() {
76*f4a2713aSLionel Sambuc   virt<elem> d; // emit 'virt<elem>'
77*f4a2713aSLionel Sambuc }
78*f4a2713aSLionel Sambuc 
79