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