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