1 // RUN: %clang -S -emit-llvm -target x86_64-unknown_unknown -g %s -o - -std=c++11 | FileCheck %s
2 
3 // CHECK: @tci = global %"struct.TC<unsigned int, 2, &glb, &foo::e, &foo::f, &foo::g, 1, 2, 3>::nested" zeroinitializer, align 1, !dbg [[TCI:![0-9]+]]
4 // CHECK: @tcn = global %struct.TC zeroinitializer, align 1, !dbg [[TCN:![0-9]+]]
5 // CHECK: @nn = global %struct.NN zeroinitializer, align 1, !dbg [[NN:![0-9]+]]
6 
7 // CHECK: !DICompileUnit(
8 // CHECK: [[EMPTY:![0-9]*]] = !{}
9 
10 struct foo {
11   char pad[8]; // make the member pointer to 'e' a bit more interesting (nonzero)
12   int e;
13   void f();
14   static void g();
15 };
16 
17 typedef int foo::*foo_mem;
18 
19 template<typename T, T, const int *x, foo_mem a, void (foo::*b)(), void (*f)(), int ...Is>
20 struct TC {
21   struct nested {
22   };
23 };
24 
25 int glb;
26 void func();
27 
28 // CHECK: [[TCI]] = distinct !DIGlobalVariable(name: "tci",
29 // CHECK-SAME:              type: ![[TCNESTED:[0-9]+]]
30 // CHECK: ![[TCNESTED]] ={{.*}}!DICompositeType(tag: DW_TAG_structure_type, name: "nested",
31 // CHECK-SAME:             scope: ![[TC:[0-9]+]],
32 
33 // CHECK: ![[TC]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "TC<unsigned int, 2, &glb, &foo::e, &foo::f, &foo::g, 1, 2, 3>"
34 // CHECK-SAME:                              templateParams: [[TCARGS:![0-9]*]]
35 TC
36 // CHECK: [[TCARGS]] = !{[[TCARG1:![0-9]*]], [[TCARG2:![0-9]*]], [[TCARG3:![0-9]*]], [[TCARG4:![0-9]*]], [[TCARG5:![0-9]*]], [[TCARG6:![0-9]*]], [[TCARG7:![0-9]*]]}
37 // CHECK: [[TCARG1]] = !DITemplateTypeParameter(name: "T", type: [[UINT:![0-9]*]])
38 // CHECK: [[UINT:![0-9]*]] = !DIBasicType(name: "unsigned int"
39 < unsigned,
40 // CHECK: [[TCARG2]] = !DITemplateValueParameter(type: [[UINT]], value: i32 2)
41   2,
42 // CHECK: [[TCARG3]] = !DITemplateValueParameter(name: "x", type: [[CINTPTR:![0-9]*]], value: i32* @glb)
43 // CHECK: [[CINTPTR]] = !DIDerivedType(tag: DW_TAG_pointer_type, {{.*}}baseType: [[CINT:![0-9]+]]
44 // CHECK: [[CINT]] = !DIDerivedType(tag: DW_TAG_const_type, {{.*}}baseType: [[INT:![0-9]+]]
45 // CHECK: [[INT]] = !DIBasicType(name: "int"
46   &glb,
47 // CHECK: [[TCARG4]] = !DITemplateValueParameter(name: "a", type: [[MEMINTPTR:![0-9]*]], value: i64 8)
48 // CHECK: [[MEMINTPTR]] = !DIDerivedType(tag: DW_TAG_ptr_to_member_type, {{.*}}baseType: [[INT]], {{.*}}extraData: ![[FOO:[0-9]+]])
49 //
50 // We could just emit a declaration of 'foo' here, rather than the entire
51 // definition (same goes for any time we emit a member (function or data)
52 // pointer type)
53 // CHECK: [[FOO]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "foo", {{.*}}identifier: "_ZTS3foo")
54 // CHECK: !DISubprogram(name: "f", linkageName: "_ZN3foo1fEv", {{.*}}type: [[FTYPE:![0-9]*]]
55 //
56 // Currently Clang emits the pointer-to-member-function value, but LLVM doesn't
57 // use it (GCC doesn't emit a value for pointers to member functions either - so
58 // it's not clear what, if any, format would be acceptable to GDB)
59 //
60 // CHECK: [[FTYPE:![0-9]*]] = !DISubroutineType(types: [[FARGS:![0-9]*]])
61 // CHECK: [[FARGS]] = !{null, [[FARG1:![0-9]*]]}
62 // CHECK: [[FARG1]] = !DIDerivedType(tag: DW_TAG_pointer_type,
63 // CHECK-SAME:                       baseType: ![[FOO]]
64 // CHECK-NOT:                        line:
65 // CHECK-SAME:                       size: 64, align: 64
66 // CHECK-NOT:                        offset: 0
67 // CHECK-SAME:                       DIFlagArtificial
68 // CHECK: [[FUNTYPE:![0-9]*]] = !DISubroutineType(types: [[FUNARGS:![0-9]*]])
69 // CHECK: [[FUNARGS]] = !{null}
70   &foo::e,
71 // CHECK: [[TCARG5]] = !DITemplateValueParameter(name: "b", type: [[MEMFUNPTR:![0-9]*]], value: { i64, i64 } { i64 ptrtoint (void (%struct.foo*)* @_ZN3foo1fEv to i64), i64 0 })
72 // CHECK: [[MEMFUNPTR]] = !DIDerivedType(tag: DW_TAG_ptr_to_member_type, {{.*}}baseType: [[FTYPE]], {{.*}}extraData: ![[FOO]])
73   &foo::f,
74 // CHECK: [[TCARG6]] = !DITemplateValueParameter(name: "f", type: [[FUNPTR:![0-9]*]], value: void ()* @_ZN3foo1gEv)
75 // CHECK: [[FUNPTR]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[FUNTYPE]]
76   &foo::g,
77 // CHECK: [[TCARG7]] = !DITemplateValueParameter(tag: DW_TAG_GNU_template_parameter_pack, name: "Is", value: [[TCARG7_VALS:![0-9]*]])
78 // CHECK: [[TCARG7_VALS]] = !{[[TCARG7_1:![0-9]*]], [[TCARG7_2:![0-9]*]], [[TCARG7_3:![0-9]*]]}
79 // CHECK: [[TCARG7_1]] = !DITemplateValueParameter(type: [[INT]], value: i32 1)
80   1,
81 // CHECK: [[TCARG7_2]] = !DITemplateValueParameter(type: [[INT]], value: i32 2)
82   2,
83 // CHECK: [[TCARG7_3]] = !DITemplateValueParameter(type: [[INT]], value: i32 3)
84   3>::nested tci;
85 
86 // CHECK: [[TCN]] = distinct !DIGlobalVariable(name: "tcn"
87 // CHECK-SAME:              type: ![[TCNT:[0-9]+]]
88 TC
89 // CHECK: ![[TCNT]] ={{.*}}!DICompositeType(tag: DW_TAG_structure_type, name: "TC<int, -3, nullptr, nullptr, nullptr, nullptr>"
90 // CHECK-SAME:             templateParams: [[TCNARGS:![0-9]*]]
91 // CHECK: [[TCNARGS]] = !{[[TCNARG1:![0-9]*]], [[TCNARG2:![0-9]*]], [[TCNARG3:![0-9]*]], [[TCNARG4:![0-9]*]], [[TCNARG5:![0-9]*]], [[TCNARG6:![0-9]*]], [[TCNARG7:![0-9]*]]}
92 // CHECK: [[TCNARG1]] = !DITemplateTypeParameter(name: "T", type: [[INT]])
93 <int,
94 // CHECK: [[TCNARG2]] = !DITemplateValueParameter(type: [[INT]], value: i32 -3)
95   -3,
96 // CHECK: [[TCNARG3]] = !DITemplateValueParameter(name: "x", type: [[CINTPTR]], value: i8 0)
97   nullptr,
98 
99 // The interesting null pointer: -1 for member data pointers (since they are
100 // just an offset in an object, they can be zero and non-null for the first
101 // member)
102 
103 // CHECK: [[TCNARG4]] = !DITemplateValueParameter(name: "a", type: [[MEMINTPTR]], value: i64 -1)
104   nullptr,
105 //
106 // In some future iteration we could possibly emit the value of a null member
107 // function pointer as '{ i64, i64 } zeroinitializer' as it may be handled
108 // naturally from the LLVM CodeGen side once we decide how to handle non-null
109 // member function pointers. For now, it's simpler just to emit the 'i8 0'.
110 //
111 // CHECK: [[TCNARG5]] = !DITemplateValueParameter(name: "b", type: [[MEMFUNPTR]], value: i8 0)
112   nullptr,
113 // CHECK: [[TCNARG6]] = !DITemplateValueParameter(name: "f", type: [[FUNPTR]], value: i8 0)
114   nullptr
115 // CHECK: [[TCNARG7]] = !DITemplateValueParameter(tag: DW_TAG_GNU_template_parameter_pack, name: "Is", value: [[EMPTY]])
116   > tcn;
117 
118 template<typename>
119 struct tmpl_impl {
120 };
121 
122 template <template <typename> class tmpl, int &lvr, int &&rvr>
123 struct NN {
124 };
125 
126 // CHECK: [[NN]] = distinct !DIGlobalVariable(name: "nn"
127 // CHECK-SAME:              type: ![[NNT:[0-9]+]]
128 
129 // FIXME: these parameters should probably be rendered as 'glb' rather than
130 // '&glb', since they're references, not pointers.
131 // CHECK: ![[NNT]] ={{.*}}!DICompositeType(tag: DW_TAG_structure_type, name: "NN<tmpl_impl, &glb, &glb>",
132 // CHECK-SAME:             templateParams: [[NNARGS:![0-9]*]]
133 // CHECK-SAME:             identifier:
134 // CHECK: [[NNARGS]] = !{[[NNARG1:![0-9]*]], [[NNARG2:![0-9]*]], [[NNARG3:![0-9]*]]}
135 // CHECK: [[NNARG1]] = !DITemplateValueParameter(tag: DW_TAG_GNU_template_template_param, name: "tmpl", value: !"tmpl_impl")
136 // CHECK: [[NNARG2]] = !DITemplateValueParameter(name: "lvr", type: [[INTLVR:![0-9]*]], value: i32* @glb)
137 // CHECK: [[INTLVR]] = !DIDerivedType(tag: DW_TAG_reference_type, baseType: [[INT]]
138 // CHECK: [[NNARG3]] = !DITemplateValueParameter(name: "rvr", type: [[INTRVR:![0-9]*]], value: i32* @glb)
139 // CHECK: [[INTRVR]] = !DIDerivedType(tag: DW_TAG_rvalue_reference_type, baseType: [[INT]]
140 NN<tmpl_impl, glb, glb> nn;
141 
142 // CHECK: ![[PADDINGATEND:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "PaddingAtEnd",
143 struct PaddingAtEnd {
144   int i;
145   char c;
146 };
147 
148 PaddingAtEnd PaddedObj = {};
149 
150 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "PaddingAtEndTemplate<&PaddedObj>"
151 // CHECK-SAME:             templateParams: [[PTOARGS:![0-9]*]]
152 // CHECK: [[PTOARGS]] = !{[[PTOARG1:![0-9]*]]}
153 // CHECK: [[PTOARG1]] = !DITemplateValueParameter(type: [[CONST_PADDINGATEND_PTR:![0-9]*]], value: %struct.PaddingAtEnd* @PaddedObj)
154 // CHECK: [[CONST_PADDINGATEND_PTR]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[PADDINGATEND]], size: 64, align: 64)
155 template <PaddingAtEnd *>
156 struct PaddingAtEndTemplate {
157 };
158 
159 PaddingAtEndTemplate<&PaddedObj> PaddedTemplateObj;
160