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