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]*}} = !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]*]] = !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]*]] = !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 // Check that the member function template specialization and implicit special 54 // members (the default ctor) refer to their class by scope, even though they 55 // didn't appear in the class's member list (C_MEM). This prevents the functions 56 // from being added to type units, while still appearing in the type 57 // declaration/reference in the compile unit. 58 // CHECK: !DISubprogram(name: "MyClass" 59 // CHECK-SAME: scope: !"_ZTS7MyClass" 60 // CHECK: !DISubprogram(name: "add<2>" 61 // CHECK-SAME: scope: !"_ZTS7MyClass" 62 63 template<typename T> 64 struct outer { 65 struct inner { 66 int i; 67 }; 68 }; 69 70 struct foo { 71 void func(outer<foo>::inner); 72 }; 73 74 inline void func() { 75 // require 'foo' to be complete before the emission of 'inner' so that, when 76 // constructing the context chain for 'x' we emit the full definition of 77 // 'foo', which requires the definition of 'inner' again 78 foo f; 79 } 80 81 outer<foo>::inner x; 82 83 // CHECK: !DIGlobalVariable(name: "x", 84 // CHECK-SAME: type: !"[[OUTER_FOO_INNER_ID]]" 85 // CHECK-SAME: variable: %"struct.outer<foo>::inner"* @x 86 87 template <typename T> 88 struct virt { 89 T* values; 90 virtual ~virt(); 91 }; 92 struct elem { 93 static virt<elem> x; // ensure that completing 'elem' will require/completing 'virt<elem>' 94 }; 95 inline void f1() { 96 elem e; // ensure 'elem' is required to be complete when it is emitted as a template argument for 'virt<elem>' 97 }; 98 void f2() { 99 virt<elem> d; // emit 'virt<elem>' 100 } 101