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