1 // RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -triple x86_64-apple-darwin %s -o - | FileCheck %s
2 
3 struct MyClass {
4   template <int i> int add(int j) {
5     return i + j;
6   }
7   virtual void func() {
8   }
9 };
10 
11 int add2(int x) {
12   return MyClass().add<2>(x);
13 }
14 
15 inline int add3(int x) {
16   return MyClass().add<3>(x); // even though add<3> is ODR used, don't emit it since we don't codegen it
17 }
18 
19 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "foo"
20 // CHECK-SAME:             elements: [[FOO_MEM:![0-9]*]]
21 // CHECK-SAME:             identifier: "_ZTS3foo"
22 // CHECK: [[FOO_MEM]] = !{[[FOO_FUNC:![0-9]*]]}
23 // CHECK: [[FOO_FUNC]] = !DISubprogram(name: "func", linkageName: "_ZN3foo4funcEN5outerIS_E5innerE",
24 // CHECK-SAME:                         type: [[FOO_FUNC_TYPE:![0-9]*]]
25 // CHECK: [[FOO_FUNC_TYPE]] = !DISubroutineType(types: [[FOO_FUNC_PARAMS:![0-9]*]])
26 // CHECK: [[FOO_FUNC_PARAMS]] = !{null, !{{[0-9]*}}, !"[[OUTER_FOO_INNER_ID:.*]]"}
27 // CHECK: !{{[0-9]*}} = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "inner"{{.*}}, identifier: "[[OUTER_FOO_INNER_ID]]")
28 
29 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "virt<elem>"
30 // CHECK-SAME:             elements: [[VIRT_MEM:![0-9]*]]
31 // CHECK-SAME:             vtableHolder: !"_ZTS4virtI4elemE"
32 // CHECK-SAME:             templateParams: [[VIRT_TEMP_PARAM:![0-9]*]]
33 // CHECK-SAME:             identifier: "_ZTS4virtI4elemE"
34 // CHECK: [[VIRT_TEMP_PARAM]] = !{[[VIRT_T:![0-9]*]]}
35 // CHECK: [[VIRT_T]] = !DITemplateTypeParameter(name: "T", type: !"_ZTS4elem")
36 
37 // CHECK: [[C:![0-9]*]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "MyClass"
38 // CHECK-SAME:                             elements: [[C_MEM:![0-9]*]]
39 // CHECK-SAME:                             vtableHolder: !"_ZTS7MyClass"
40 // CHECK-SAME:                             identifier: "_ZTS7MyClass")
41 // CHECK: [[C_MEM]] = !{[[C_VPTR:![0-9]*]], [[C_FUNC:![0-9]*]]}
42 // CHECK: [[C_VPTR]] = !DIDerivedType(tag: DW_TAG_member, name: "_vptr$MyClass"
43 
44 // CHECK: [[C_FUNC]] = !DISubprogram(name: "func",{{.*}} line: 7,
45 
46 // CHECK: [[ELEM:![0-9]*]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "elem"
47 // CHECK-SAME:                                elements: [[ELEM_MEM:![0-9]*]]
48 // CHECK-SAME:                                identifier: "_ZTS4elem"
49 // CHECK: [[ELEM_MEM]] = !{[[ELEM_X:![0-9]*]]}
50 // CHECK: [[ELEM_X]] = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !"_ZTS4elem"
51 // CHECK-SAME:                        baseType: !"_ZTS4virtI4elemE"
52 
53 
54 template<typename T>
55 struct outer {
56   struct inner {
57     int i;
58   };
59 };
60 
61 struct foo {
62   void func(outer<foo>::inner);
63 };
64 
65 inline void func() {
66   // require 'foo' to be complete before the emission of 'inner' so that, when
67   // constructing the context chain for 'x' we emit the full definition of
68   // 'foo', which requires the definition of 'inner' again
69   foo f;
70 }
71 
72 outer<foo>::inner x;
73 
74 // CHECK: !DIGlobalVariable(name: "x",
75 // CHECK-SAME:              type: !"[[OUTER_FOO_INNER_ID]]"
76 // CHECK-SAME:              variable: %"struct.outer<foo>::inner"* @x
77 
78 template <typename T>
79 struct virt {
80   T* values;
81   virtual ~virt();
82 };
83 struct elem {
84   static virt<elem> x; // ensure that completing 'elem' will require/completing 'virt<elem>'
85 };
86 inline void f1() {
87   elem e; // ensure 'elem' is required to be complete when it is emitted as a template argument for 'virt<elem>'
88 };
89 void f2() {
90   virt<elem> d; // emit 'virt<elem>'
91 }
92 
93 // Check that the member function template specialization and implicit special
94 // members (the default ctor) refer to their class by scope, even though they
95 // didn't appear in the class's member list (C_MEM). This prevents the functions
96 // from being added to type units, while still appearing in the type
97 // declaration/reference in the compile unit.
98 // CHECK: !DISubprogram(name: "MyClass"
99 // CHECK-SAME:          scope: !"_ZTS7MyClass"
100 // CHECK: !DISubprogram(name: "add<2>"
101 // CHECK-SAME:          scope: !"_ZTS7MyClass"
102